Lines Matching +full:cs +full:- +full:2
4 * Copyright (c) 1996-1999 Whistle Communications, Inc.
13 * 2. No rights are granted, in any manner or form, to use Whistle
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
55 static int NgDeliverMsg(int cs, const char *path,
59 * Send a message to a node using control socket node "cs".
60 * Returns -1 if error and sets errno appropriately.
64 NgSendMsg(int cs, const char *path, in NgSendMsg() argument
79 if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0) in NgSendMsg()
80 return (-1); in NgSendMsg()
89 NgSendAsciiMsg(int cs, const char *path, const char *fmt, ...) in NgSendAsciiMsg() argument
101 return (-1); in NgSendAsciiMsg()
117 return (-1); in NgSendAsciiMsg()
122 strncpy((char *)ascii->header.cmdstr, cmd, in NgSendAsciiMsg()
123 sizeof(ascii->header.cmdstr) - 1); in NgSendAsciiMsg()
124 strcpy(ascii->data, args); in NgSendAsciiMsg()
125 ascii->header.arglen = strlen(ascii->data) + 1; in NgSendAsciiMsg()
129 if (NgSendMsg(cs, path, NGM_GENERIC_COOKIE, NGM_ASCII2BINARY, in NgSendAsciiMsg()
130 (u_char *)ascii, sizeof(*ascii) + ascii->header.arglen) < 0) { in NgSendAsciiMsg()
132 return (-1); in NgSendAsciiMsg()
137 if (NgAllocRecvMsg(cs, &reply, NULL) < 0) in NgSendAsciiMsg()
138 return (-1); in NgSendAsciiMsg()
141 binary = (struct ng_mesg *)reply->data; in NgSendAsciiMsg()
142 binary->header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; in NgSendAsciiMsg()
143 binary->header.version = NG_VERSION; in NgSendAsciiMsg()
144 if (NgDeliverMsg(cs, in NgSendAsciiMsg()
145 path, binary, binary->data, binary->header.arglen) < 0) { in NgSendAsciiMsg()
147 return (-1); in NgSendAsciiMsg()
149 token = binary->header.token; in NgSendAsciiMsg()
156 * Returns -1 and sets errno on error, otherwise returns zero.
159 NgSendReplyMsg(int cs, const char *path, in NgSendReplyMsg() argument
169 return (NgDeliverMsg(cs, path, &rep, args, arglen)); in NgSendReplyMsg()
173 * Send a message to a node using control socket node "cs".
174 * Returns -1 if error and sets errno appropriately, otherwise zero.
177 NgDeliverMsg(int cs, const char *path, in NgDeliverMsg() argument
196 rtn = -1; in NgDeliverMsg()
203 msg->header.arglen = arglen; in NgDeliverMsg()
204 memcpy(msg->data, args, arglen); in NgDeliverMsg()
207 sg->sg_family = AF_NETGRAPH; in NgDeliverMsg()
209 strlcpy(sg->sg_data, path, NG_PATHSIZ); in NgDeliverMsg()
210 sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD; in NgDeliverMsg()
213 if (_gNgDebugLevel >= 2) { in NgDeliverMsg()
215 (msg->header.flags & NGF_RESP) ? "RESPONSE" : "MESSAGE"); in NgDeliverMsg()
217 _NgDebugMsg(msg, sg->sg_data); in NgDeliverMsg()
221 if (sendto(cs, msg, sizeof(*msg) + arglen, in NgDeliverMsg()
222 0, (struct sockaddr *) sg, sg->sg_len) < 0) { in NgDeliverMsg()
225 NGLOG("sendto(%s)", sg->sg_data); in NgDeliverMsg()
226 rtn = -1; in NgDeliverMsg()
231 if (msg->header.cmd & NGM_HASREPLY && !(msg->header.flags & NGF_RESP)) { in NgDeliverMsg()
235 rfds.fd = cs; in NgDeliverMsg()
239 if (n == -1) { in NgDeliverMsg()
243 rtn = -1; in NgDeliverMsg()
257 * On error, this returns -1 and sets errno.
261 NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path) in NgRecvMsg() argument
269 len = recvfrom(cs, rep, replen, 0, (struct sockaddr *) sg, &sglen); in NgRecvMsg()
277 strlcpy(path, sg->sg_data, NG_PATHSIZ); in NgRecvMsg()
280 if (_gNgDebugLevel >= 2) { in NgRecvMsg()
282 (rep->header.flags & NGF_RESP) ? "RESPONSE" : "MESSAGE"); in NgRecvMsg()
284 _NgDebugMsg(rep, sg->sg_data); in NgRecvMsg()
292 return (-1); in NgRecvMsg()
299 NgAllocRecvMsg(int cs, struct ng_mesg **rep, char *path) in NgAllocRecvMsg() argument
305 if (getsockopt(cs, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1 || in NgAllocRecvMsg()
307 return (-1); in NgAllocRecvMsg()
308 if ((len = NgRecvMsg(cs, *rep, len, path)) < 0) in NgAllocRecvMsg()
317 NgRecvAsciiMsg(int cs, struct ng_mesg *reply, size_t replen, char *path) in NgRecvAsciiMsg() argument
324 bufSize = 2 * sizeof(*reply) + replen; in NgRecvAsciiMsg()
326 return (-1); in NgRecvAsciiMsg()
328 ascii = (struct ng_mesg *)msg->data; in NgRecvAsciiMsg()
331 if (NgRecvMsg(cs, msg, bufSize, path) < 0) in NgRecvAsciiMsg()
336 if (NgSendMsg(cs, path, NGM_GENERIC_COOKIE, in NgRecvAsciiMsg()
337 NGM_BINARY2ASCII, msg, sizeof(*msg) + msg->header.arglen) < 0) in NgRecvAsciiMsg()
339 if (NgRecvMsg(cs, msg, bufSize, NULL) < 0) in NgRecvAsciiMsg()
343 if (sizeof(*ascii) + ascii->header.arglen > replen) { in NgRecvAsciiMsg()
349 return (-1); in NgRecvAsciiMsg()
351 strncpy(reply->data, ascii->data, ascii->header.arglen); in NgRecvAsciiMsg()
362 NgAllocRecvAsciiMsg(int cs, struct ng_mesg **reply, char *path) in NgAllocRecvAsciiMsg() argument
368 if (getsockopt(cs, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1 || in NgAllocRecvAsciiMsg()
370 return (-1); in NgAllocRecvAsciiMsg()
371 if ((len = NgRecvAsciiMsg(cs, *reply, len, path)) < 0) in NgAllocRecvAsciiMsg()