]>
git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/moh.c
2 * Copyright (c) 2002, 2003, 2005, 2013-2015 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * May 29, 2002 Roger Smith <rsmith@apple.com>
33 #include <sys/types.h>
34 #include <sys/errno.h>
35 #include <sys/socket.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
, size_t len
)
58 if ((n
= read(ref
, p
, left
)) == -1) {
75 writen(int ref
, const void *data
, size_t len
)
82 if ((n
= write(ref
, p
, left
)) == -1) {
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
) == -1) {
140 struct moh_msg_hdr msg
;
144 bzero(&msg
, sizeof(msg
));
147 msg
.m_len
= ((request
!= NULL
) && (requestLen
> 0)) ? (uint32_t)requestLen
: 0;
150 n
= writen(ref
, &msg
, sizeof(msg
));
152 SC_log(LOG_INFO
, "writen() failed: %s", strerror(errno
));
154 } else if (n
!= sizeof(msg
)) {
155 SC_log(LOG_INFO
, "writen() failed: wrote=%ld", n
);
159 if ((request
!= NULL
) && (requestLen
> 0)) {
160 n
= writen(ref
, request
, requestLen
);
162 SC_log(LOG_INFO
, "writen() failed: %s", strerror(errno
));
164 } else if (n
!= (ssize_t
)requestLen
) {
165 SC_log(LOG_INFO
, "writen() failed: wrote=%ld", n
);
170 // always expect a reply
171 n
= readn(ref
, &msg
, sizeof(msg
));
173 SC_log(LOG_INFO
, "readn() failed: error=%s", strerror(errno
));
175 } else if (n
!= sizeof(msg
)) {
176 SC_log(LOG_INFO
, "readn() failed: insufficent data, read=%ld", n
);
181 buf
= CFAllocatorAllocate(NULL
, msg
.m_len
, 0);
184 n
= readn(ref
, buf
, msg
.m_len
);
186 SC_log(LOG_INFO
, "readn() failed: error=%s", strerror(errno
));
187 CFAllocatorDeallocate(NULL
, buf
);
189 } else if (n
!= (ssize_t
)msg
.m_len
) {
190 SC_log(LOG_INFO
, "readn() failed: insufficent data, read=%ld", 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
);