]>
git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/moh.c
2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * May 29, 2002 Roger Smith <rsmith@apple.com>
32 #include <sys/types.h>
33 #include <sys/errno.h>
34 #include <sys/socket.h>
36 #include <CoreFoundation/CoreFoundation.h>
38 #include <SystemConfiguration/SystemConfiguration.h>
39 #include <SystemConfiguration/SCPrivate.h>
44 // Note: right now we are not currently using the deviceName. This could be the raw
45 // tty name such as "modem" since this is guaranteed to be unique in the /dev.
46 // We would use this deviceName to differientate between multiple MOH devices
47 // present in the system when we create the socket.
51 readn(int ref
, void *data
, int len
)
58 if ((n
= read(ref
, p
, left
)) < 0) {
75 writen(int ref
, void *data
, int len
)
82 if ((n
= write(ref
, p
, left
)) <= 0) {
97 MOHInit(int *ref
, CFStringRef deviceName
)
101 struct sockaddr_un sun
;
103 sock
= socket(AF_LOCAL
, SOCK_STREAM
, 0);
105 bzero(&sun
, sizeof(sun
));
106 sun
.sun_family
= AF_LOCAL
;
107 strncpy(sun
.sun_path
, MOH_PATH
, sizeof(sun
.sun_path
));
109 status
= connect(sock
, (struct sockaddr
*)&sun
, sizeof(sun
));
123 if (close(ref
) < 0) {
140 struct moh_msg_hdr msg
;
144 bzero(&msg
, sizeof(msg
));
147 msg
.m_len
= ((request
!= NULL
) && (requestLen
> 0)) ? requestLen
: 0;
150 n
= writen(ref
, &msg
, sizeof(msg
));
152 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec writen() failed: %s"), strerror(errno
));
154 } else if (n
!= sizeof(msg
)) {
155 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec writen() failed: wrote=%d"), n
);
159 if ((request
!= NULL
) && (requestLen
> 0)) {
160 n
= writen(ref
, request
, requestLen
);
162 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec writen() failed: %s"), strerror(errno
));
164 } else if (n
!= requestLen
) {
165 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec writen() failed: wrote=%d"), n
);
170 // always expect a reply
171 n
= readn(ref
, &msg
, sizeof(msg
));
173 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec readn() failed: error=%s"), strerror(errno
));
175 } else if (n
!= sizeof(msg
)) {
176 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec readn() failed: insufficent data, read=%d"), n
);
181 buf
= CFAllocatorAllocate(NULL
, msg
.m_len
, 0);
184 n
= readn(ref
, buf
, msg
.m_len
);
186 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec readn() failed: error=%s"), strerror(errno
));
187 CFAllocatorDeallocate(NULL
, buf
);
189 } else if (n
!= msg
.m_len
) {
190 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec readn() failed: insufficent data, read=%d"), n
);
191 CFAllocatorDeallocate(NULL
, buf
);
197 if (reply
&& replyLen
) {
199 *replyLen
= msg
.m_len
;
201 // if additional returned data is unwanted
202 CFAllocatorDeallocate(NULL
, buf
);