debug.c (baa60a3b175739c68b9eaf6797ed415ef38ad2c3) debug.c (1816e452a68495dd37b5800d1aceee4a957fead8)
1
2/*
3 * debug.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 157 unchanged lines hidden (view full) ---

166 */
167void
168_NgDebugSockaddr(const struct sockaddr_ng *sg)
169{
170 NGLOGX("SOCKADDR: { fam=%d len=%d addr=\"%s\" }",
171 sg->sg_family, sg->sg_len, sg->sg_data);
172}
173
1
2/*
3 * debug.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 157 unchanged lines hidden (view full) ---

166 */
167void
168_NgDebugSockaddr(const struct sockaddr_ng *sg)
169{
170 NGLOGX("SOCKADDR: { fam=%d len=%d addr=\"%s\" }",
171 sg->sg_family, sg->sg_len, sg->sg_data);
172}
173
174#define ARGS_BUFSIZE 1024
174#define ARGS_BUFSIZE 2048
175#define RECURSIVE_DEBUG_ADJUST 4
175
176/*
177 * Display a negraph message
178 */
179void
180_NgDebugMsg(const struct ng_mesg *msg, const char *path)
181{
182 u_char buf[2 * sizeof(struct ng_mesg) + ARGS_BUFSIZE];
183 struct ng_mesg *const req = (struct ng_mesg *)buf;
184 struct ng_mesg *const bin = (struct ng_mesg *)req->data;
176
177/*
178 * Display a negraph message
179 */
180void
181_NgDebugMsg(const struct ng_mesg *msg, const char *path)
182{
183 u_char buf[2 * sizeof(struct ng_mesg) + ARGS_BUFSIZE];
184 struct ng_mesg *const req = (struct ng_mesg *)buf;
185 struct ng_mesg *const bin = (struct ng_mesg *)req->data;
185 int arglen, debugSave, csock = -1;
186 int arglen, csock = -1;
186
187
187 /* Lower debugging to avoid infinite recursion */
188 debugSave = _gNgDebugLevel;
189 _gNgDebugLevel -= 4;
190
191 /* Display header stuff */
192 NGLOGX("NG_MESG :");
193 NGLOGX(" vers %d", msg->header.version);
194 NGLOGX(" arglen %d", msg->header.arglen);
195 NGLOGX(" flags %ld", msg->header.flags);
196 NGLOGX(" token %lu", (u_long)msg->header.token);
197 NGLOGX(" cookie %s (%d)",
198 NgCookie(msg->header.typecookie), msg->header.typecookie);

--- 13 unchanged lines hidden (view full) ---

212
213 /* Copy binary message into request message payload */
214 arglen = msg->header.arglen;
215 if (arglen > ARGS_BUFSIZE)
216 arglen = ARGS_BUFSIZE;
217 memcpy(bin, msg, sizeof(*msg) + arglen);
218 bin->header.arglen = arglen;
219
188 /* Display header stuff */
189 NGLOGX("NG_MESG :");
190 NGLOGX(" vers %d", msg->header.version);
191 NGLOGX(" arglen %d", msg->header.arglen);
192 NGLOGX(" flags %ld", msg->header.flags);
193 NGLOGX(" token %lu", (u_long)msg->header.token);
194 NGLOGX(" cookie %s (%d)",
195 NgCookie(msg->header.typecookie), msg->header.typecookie);

--- 13 unchanged lines hidden (view full) ---

209
210 /* Copy binary message into request message payload */
211 arglen = msg->header.arglen;
212 if (arglen > ARGS_BUFSIZE)
213 arglen = ARGS_BUFSIZE;
214 memcpy(bin, msg, sizeof(*msg) + arglen);
215 bin->header.arglen = arglen;
216
217 /* Lower debugging to avoid infinite recursion */
218 _gNgDebugLevel -= RECURSIVE_DEBUG_ADJUST;
219
220 /* Ask the node to translate the binary message to ASCII for us */
221 if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
220 /* Ask the node to translate the binary message to ASCII for us */
221 if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
222 NGM_BINARY2ASCII, bin, sizeof(*bin) + bin->header.arglen) < 0)
222 NGM_BINARY2ASCII, bin, sizeof(*bin) + bin->header.arglen) < 0) {
223 _gNgDebugLevel += RECURSIVE_DEBUG_ADJUST;
223 goto fail;
224 goto fail;
224 if (NgRecvMsg(csock, req, sizeof(buf), NULL) < 0)
225 }
226 if (NgRecvMsg(csock, req, sizeof(buf), NULL) < 0) {
227 _gNgDebugLevel += RECURSIVE_DEBUG_ADJUST;
225 goto fail;
228 goto fail;
229 }
226
230
231 /* Restore debugging level */
232 _gNgDebugLevel += RECURSIVE_DEBUG_ADJUST;
233
227 /* Display command string and arguments */
228 NGLOGX(" cmd %s (%d)", bin->header.cmdstr, bin->header.cmd);
229 NGLOGX(" args %s", bin->data);
230 goto done;
231
232fail:
233 /* Just display binary version */
234 NGLOGX(" [error decoding message: %s]", strerror(errno));
235fail2:
236 NGLOGX(" cmd %d", msg->header.cmd);
237 NGLOGX(" args (%d bytes)", msg->header.arglen);
238 _NgDebugBytes(msg->data, msg->header.arglen);
239
240done:
241 if (csock != -1)
242 (void)close(csock);
234 /* Display command string and arguments */
235 NGLOGX(" cmd %s (%d)", bin->header.cmdstr, bin->header.cmd);
236 NGLOGX(" args %s", bin->data);
237 goto done;
238
239fail:
240 /* Just display binary version */
241 NGLOGX(" [error decoding message: %s]", strerror(errno));
242fail2:
243 NGLOGX(" cmd %d", msg->header.cmd);
244 NGLOGX(" args (%d bytes)", msg->header.arglen);
245 _NgDebugBytes(msg->data, msg->header.arglen);
246
247done:
248 if (csock != -1)
249 (void)close(csock);
243 _gNgDebugLevel = debugSave;
244}
245
246/*
247 * Return the name of the node type corresponding to the cookie
248 */
249static const char *
250NgCookie(int cookie)
251{

--- 50 unchanged lines hidden ---
250}
251
252/*
253 * Return the name of the node type corresponding to the cookie
254 */
255static const char *
256NgCookie(int cookie)
257{

--- 50 unchanged lines hidden ---