]>
git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/moh.c
2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * May 29, 2002 Roger Smith <rsmith@apple.com>
35 #include <sys/types.h>
36 #include <sys/errno.h>
37 #include <sys/socket.h>
40 #include <SystemConfiguration/SystemConfiguration.h>
41 #include <SystemConfiguration/SCPrivate.h>
46 // Note: right now we are not currently using the deviceName. This could be the raw
47 // tty name such as "modem" since this is guaranteed to be unique in the /dev.
48 // We would use this deviceName to differientate between multiple MOH devices
49 // present in the system when we create the socket.
53 readn(int ref
, void *data
, int len
)
60 if ((n
= read(ref
, p
, left
)) < 0) {
77 writen(int ref
, void *data
, int len
)
84 if ((n
= write(ref
, p
, left
)) <= 0) {
99 MOHInit(int *ref
, CFStringRef deviceName
)
103 struct sockaddr_un sun
;
105 sock
= socket(AF_LOCAL
, SOCK_STREAM
, 0);
107 bzero(&sun
, sizeof(sun
));
108 sun
.sun_family
= AF_LOCAL
;
109 strncpy(sun
.sun_path
, MOH_PATH
, sizeof(sun
.sun_path
));
111 status
= connect(sock
, (struct sockaddr
*)&sun
, sizeof(sun
));
125 if (close(ref
) < 0) {
142 struct moh_msg_hdr msg
;
146 bzero(&msg
, sizeof(msg
));
149 msg
.m_len
= ((request
!= NULL
) && (requestLen
> 0)) ? requestLen
: 0;
152 n
= writen(ref
, &msg
, sizeof(msg
));
154 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec writen() failed: %s"), strerror(errno
));
156 } else if (n
!= sizeof(msg
)) {
157 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec writen() failed: wrote=%d"), n
);
161 if ((request
!= NULL
) && (requestLen
> 0)) {
162 n
= writen(ref
, request
, requestLen
);
164 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec writen() failed: %s"), strerror(errno
));
166 } else if (n
!= (ssize_t
)requestLen
) {
167 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec writen() failed: wrote=%d"), n
);
172 // always expect a reply
173 n
= readn(ref
, &msg
, sizeof(msg
));
175 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec readn() failed: error=%s"), strerror(errno
));
177 } else if (n
!= sizeof(msg
)) {
178 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec readn() failed: insufficent data, read=%d"), n
);
183 buf
= CFAllocatorAllocate(NULL
, msg
.m_len
, 0);
186 n
= readn(ref
, buf
, msg
.m_len
);
188 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec readn() failed: error=%s"), strerror(errno
));
189 CFAllocatorDeallocate(NULL
, buf
);
191 } else if (n
!= (ssize_t
)msg
.m_len
) {
192 SCLog(_sc_verbose
, LOG_ERR
, CFSTR("MOHExec readn() failed: insufficent data, read=%d"), n
);
193 CFAllocatorDeallocate(NULL
, buf
);
199 if (reply
&& replyLen
) {
201 *replyLen
= msg
.m_len
;
203 // if additional returned data is unwanted
204 CFAllocatorDeallocate(NULL
, buf
);