Project

General

Profile

Bug #675 » netgraph-remove-xLEN2.patch

nant, 06/03/2007 11:16 PM

View differences:

lib/libnetgraph/sock.c 2007-06-03 23:41:19.000000000 +0100
int
NgMkSockNode(const char *name, int *csp, int *dsp)
{
char namebuf[NG_NODELEN + 1];
char namebuf[NG_NODESIZ];
int cs = -1; /* control socket */
int ds = -1; /* data socket */
int errnosv;
......
gotNode:
/* Assign the node the desired name, if any */
if (name != NULL) {
u_char sbuf[NG_NODELEN + 3];
u_char sbuf[NG_NODESIZ + 2];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf;
/* Assign name */
snprintf(sg->sg_data, NG_NODELEN + 1, "%s", name);
snprintf(sg->sg_data, NG_NODESIZ, "%s", name);
sg->sg_family = AF_NETGRAPH;
sg->sg_len = strlen(sg->sg_data) + 3;
if (bind(cs, (struct sockaddr *) sg, sg->sg_len) < 0) {
......
/* Create data socket if desired */
if (dsp != NULL) {
u_char sbuf[NG_NODELEN + 4];
u_char sbuf[NG_NODESIZ + 3];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf;
/* Create data socket, initially just "floating" */
......
}
/* Associate the data socket with the node */
snprintf(sg->sg_data, NG_NODELEN + 2, "%s:", namebuf);
snprintf(sg->sg_data, NG_NODESIZ + 1, "%s:", namebuf);
sg->sg_family = AF_NETGRAPH;
sg->sg_len = strlen(sg->sg_data) + 3;
if (connect(ds, (struct sockaddr *) sg, sg->sg_len) < 0) {
......
int
NgRecvData(int ds, u_char * buf, size_t len, char *hook)
{
u_char frombuf[NG_HOOKLEN + sizeof(struct sockaddr_ng)];
u_char frombuf[NG_HOOKSIZ - 1 + sizeof(struct sockaddr_ng)];
struct sockaddr_ng *const from = (struct sockaddr_ng *) frombuf;
int fromlen = sizeof(frombuf);
int rtn, errnosv;
......
/* Copy hook name */
if (hook != NULL)
snprintf(hook, NG_HOOKLEN + 1, "%s", from->sg_data);
snprintf(hook, NG_HOOKSIZ, "%s", from->sg_data);
/* Debugging */
if (_gNgDebugLevel >= 2) {
......
int
NgSendData(int ds, const char *hook, const u_char * buf, size_t len)
{
u_char sgbuf[NG_HOOKLEN + sizeof(struct sockaddr_ng)];
u_char sgbuf[NG_HOOKSIZ - 1 + sizeof(struct sockaddr_ng)];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
int errnosv;
/* Set up destination hook */
sg->sg_family = AF_NETGRAPH;
snprintf(sg->sg_data, NG_HOOKLEN + 1, "%s", hook);
snprintf(sg->sg_data, NG_HOOKSIZ, "%s", hook);
sg->sg_len = strlen(sg->sg_data) + 3;
/* Debugging */
-- lib/libnetgraph/msg.c.orig 2007-06-03 23:38:47.000000000 +0100
++ lib/libnetgraph/msg.c 2007-06-03 23:40:03.000000000 +0100
......
msg.header.token = gMsgId;
msg.header.flags = NGF_ORIG;
msg.header.cmd = cmd;
snprintf(msg.header.cmdstr, NG_CMDSTRLEN + 1, "cmd%d", cmd);
snprintf(msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd);
/* Deliver message */
if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0)
......
NgDeliverMsg(int cs, const char *path,
const struct ng_mesg *hdr, const void *args, size_t arglen)
{
u_char sgbuf[NG_PATHLEN + 3];
u_char sgbuf[NG_PATHSIZ + 2];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
u_char *buf = NULL;
struct ng_mesg *msg;
......
/* Prepare socket address */
sg->sg_family = AF_NETGRAPH;
snprintf(sg->sg_data, NG_PATHLEN + 1, "%s", path);
snprintf(sg->sg_data, NG_PATHSIZ, "%s", path);
sg->sg_len = strlen(sg->sg_data) + 3;
/* Debugging */
......
int
NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path)
{
u_char sgbuf[NG_PATHLEN + sizeof(struct sockaddr_ng)];
u_char sgbuf[NG_PATHSIZ - 1 + sizeof(struct sockaddr_ng)];
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
int len, sglen = sizeof(sgbuf);
int errnosv;
......
goto errout;
}
if (path != NULL)
snprintf(path, NG_PATHLEN + 1, "%s", sg->sg_data);
snprintf(path, NG_PATHSIZ, "%s", sg->sg_data);
/* Debugging */
if (_gNgDebugLevel >= 2) {
-- lib/libnetgraph/netgraph.3.orig 2007-06-03 23:55:34.000000000 +0100
++ lib/libnetgraph/netgraph.3 2007-06-03 23:53:17.000000000 +0100
......
If
.Fa "path"
is non-NULL, it must point to a buffer of at least
.Dv "NG_PATHLEN + 1"
.Dv "NG_PATHSIZ"
bytes, which will be filled in (and NUL terminated) with the path to
the node from which the message was received.
.Pp
......
which must be large enough to hold the entire packet. If
.Fa "hook"
is non-NULL, it must point to a buffer of at least
.Dv "NG_HOOKLEN + 1"
.Dv "NG_HOOKSIZ"
bytes, which will be filled in (and NUL terminated) with the name of
the hook on which the data was received.
.Pp
(2-2/3)