summaryrefslogtreecommitdiffstats
path: root/sys/netinet/libalias/alias_nbt.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2004-03-16 21:30:41 +0000
committerdes <des@FreeBSD.org>2004-03-16 21:30:41 +0000
commit3cb81148d8a83b1e6c1a65937f9e6310ba617894 (patch)
treeb367873b0bbb14ba0adf2f65c33ec1670b035d30 /sys/netinet/libalias/alias_nbt.c
parent0354260aab76815ce0d09458a84211e4b9e58979 (diff)
downloadFreeBSD-src-3cb81148d8a83b1e6c1a65937f9e6310ba617894.zip
FreeBSD-src-3cb81148d8a83b1e6c1a65937f9e6310ba617894.tar.gz
Run through indent(1) so I can read the code without getting a headache.
The result isn't quite knf, but it's knfer than the original, and far more consistent.
Diffstat (limited to 'sys/netinet/libalias/alias_nbt.c')
-rw-r--r--sys/netinet/libalias/alias_nbt.c672
1 files changed, 337 insertions, 335 deletions
diff --git a/sys/netinet/libalias/alias_nbt.c b/sys/netinet/libalias/alias_nbt.c
index 9ff9cf0..fc5fa84 100644
--- a/sys/netinet/libalias/alias_nbt.c
+++ b/sys/netinet/libalias/alias_nbt.c
@@ -55,22 +55,22 @@ __FBSDID("$FreeBSD$");
#include "alias_local.h"
typedef struct {
- struct in_addr oldaddr;
- u_short oldport;
- struct in_addr newaddr;
- u_short newport;
- u_short *uh_sum;
-} NBTArguments;
+ struct in_addr oldaddr;
+ u_short oldport;
+ struct in_addr newaddr;
+ u_short newport;
+ u_short *uh_sum;
+} NBTArguments;
typedef struct {
- unsigned char type;
- unsigned char flags;
- u_short id;
- struct in_addr source_ip;
- u_short source_port;
- u_short len;
- u_short offset;
-} NbtDataHeader;
+ unsigned char type;
+ unsigned char flags;
+ u_short id;
+ struct in_addr source_ip;
+ u_short source_port;
+ u_short len;
+ u_short offset;
+} NbtDataHeader;
#define OpQuery 0
#define OpUnknown 4
@@ -79,13 +79,13 @@ typedef struct {
#define OpWACK 7
#define OpRefresh 8
typedef struct {
- u_short nametrid;
- u_short dir:1, opcode:4, nmflags:7, rcode:4;
- u_short qdcount;
- u_short ancount;
- u_short nscount;
- u_short arcount;
-} NbtNSHeader;
+ u_short nametrid;
+ u_short dir: 1, opcode:4, nmflags:7, rcode:4;
+ u_short qdcount;
+ u_short ancount;
+ u_short nscount;
+ u_short arcount;
+} NbtNSHeader;
#define FMT_ERR 0x1
#define SRV_ERR 0x2
@@ -96,56 +96,61 @@ typedef struct {
#ifdef DEBUG
-static void PrintRcode( u_char rcode ) {
+static void
+PrintRcode(u_char rcode)
+{
switch (rcode) {
case FMT_ERR:
- printf("\nFormat Error.");
- case SRV_ERR:
- printf("\nSever failure.");
- case IMP_ERR:
- printf("\nUnsupported request error.\n");
- case RFS_ERR:
- printf("\nRefused error.\n");
- case ACT_ERR:
- printf("\nActive error.\n");
- case CFT_ERR:
- printf("\nName in conflict error.\n");
- default:
- printf("\n?%c?=%0x\n", '?', rcode );
+ printf("\nFormat Error.");
+ case SRV_ERR:
+ printf("\nSever failure.");
+ case IMP_ERR:
+ printf("\nUnsupported request error.\n");
+ case RFS_ERR:
+ printf("\nRefused error.\n");
+ case ACT_ERR:
+ printf("\nActive error.\n");
+ case CFT_ERR:
+ printf("\nName in conflict error.\n");
+ default:
+ printf("\n?%c?=%0x\n", '?', rcode);
}
}
+
#endif
/* Handling Name field */
-static u_char *AliasHandleName ( u_char *p, char *pmax ) {
+static u_char *
+AliasHandleName(u_char * p, char *pmax)
+{
u_char *s;
u_char c;
- int compress;
+ int compress;
/* Following length field */
if (p == NULL || (char *)p >= pmax)
- return(NULL);
+ return (NULL);
- if (*p & 0xc0 ) {
+ if (*p & 0xc0) {
p = p + 2;
if ((char *)p > pmax)
- return(NULL);
- return ((u_char *)p);
+ return (NULL);
+ return ((u_char *) p);
}
- while ( ( *p & 0x3f) != 0x00 ) {
+ while ((*p & 0x3f) != 0x00) {
s = p + 1;
- if ( *p == 0x20 )
+ if (*p == 0x20)
compress = 1;
else
compress = 0;
- /* Get next length field */
- p = (u_char *)(p + (*p & 0x3f) + 1);
+ /* Get next length field */
+ p = (u_char *) (p + (*p & 0x3f) + 1);
if ((char *)p > pmax) {
p = NULL;
break;
@@ -154,15 +159,15 @@ static u_char *AliasHandleName ( u_char *p, char *pmax ) {
printf(":");
#endif
while (s < p) {
- if ( compress == 1 ) {
- c = (u_char )(((((*s & 0x0f) << 4) | (*(s+1) & 0x0f)) - 0x11));
+ if (compress == 1) {
+ c = (u_char) (((((*s & 0x0f) << 4) | (*(s + 1) & 0x0f)) - 0x11));
#ifdef DEBUG
- if (isprint( c ) )
- printf("%c", c );
+ if (isprint(c))
+ printf("%c", c);
else
- printf("<0x%02x>", c );
+ printf("<0x%02x>", c);
#endif
- s +=2;
+ s += 2;
} else {
#ifdef DEBUG
printf("%c", *s);
@@ -174,14 +179,14 @@ static u_char *AliasHandleName ( u_char *p, char *pmax ) {
printf(":");
#endif
fflush(stdout);
- }
+ }
/* Set up to out of Name field */
if (p == NULL || (char *)p >= pmax)
- p = NULL;
+ p = NULL;
else
- p++;
- return ((u_char *)p);
+ p++;
+ return ((u_char *) p);
}
/*
@@ -195,58 +200,61 @@ static u_char *AliasHandleName ( u_char *p, char *pmax ) {
#define DGM_POSITIVE_RES 0x15
#define DGM_NEGATIVE_RES 0x16
-int AliasHandleUdpNbt(
- struct libalias *la,
- struct ip *pip, /* IP packet to examine/patch */
- struct alias_link *link,
- struct in_addr *alias_address,
- u_short alias_port
-) {
- struct udphdr * uh;
- NbtDataHeader *ndh;
- u_char *p = NULL;
- char *pmax;
-
- /* Calculate data length of UDP packet */
- uh = (struct udphdr *) ((char *) pip + (pip->ip_hl << 2));
- pmax = (char *)uh + ntohs( uh->uh_ulen );
-
- ndh = (NbtDataHeader *)((char *)uh + (sizeof (struct udphdr)));
- if ((char *)(ndh + 1) > pmax)
- return(-1);
+int
+AliasHandleUdpNbt(
+ struct libalias *la,
+ struct ip *pip, /* IP packet to examine/patch */
+ struct alias_link *link,
+ struct in_addr *alias_address,
+ u_short alias_port
+)
+{
+ struct udphdr *uh;
+ NbtDataHeader *ndh;
+ u_char *p = NULL;
+ char *pmax;
+
+ /* Calculate data length of UDP packet */
+ uh = (struct udphdr *)((char *)pip + (pip->ip_hl << 2));
+ pmax = (char *)uh + ntohs(uh->uh_ulen);
+
+ ndh = (NbtDataHeader *) ((char *)uh + (sizeof(struct udphdr)));
+ if ((char *)(ndh + 1) > pmax)
+ return (-1);
#ifdef DEBUG
- printf("\nType=%02x,", ndh->type );
+ printf("\nType=%02x,", ndh->type);
#endif
- switch ( ndh->type ) {
- case DGM_DIRECT_UNIQ:
- case DGM_DIRECT_GROUP:
- case DGM_BROADCAST:
- p = (u_char *)ndh + 14;
- p = AliasHandleName ( p, pmax ); /* Source Name */
- p = AliasHandleName ( p, pmax ); /* Destination Name */
- break;
- case DGM_ERROR:
- p = (u_char *)ndh + 11;
- break;
- case DGM_QUERY:
- case DGM_POSITIVE_RES:
- case DGM_NEGATIVE_RES:
- p = (u_char *)ndh + 10;
- p = AliasHandleName ( p, pmax ); /* Destination Name */
- break;
+ switch (ndh->type) {
+ case DGM_DIRECT_UNIQ:
+ case DGM_DIRECT_GROUP:
+ case DGM_BROADCAST:
+ p = (u_char *) ndh + 14;
+ p = AliasHandleName(p, pmax); /* Source Name */
+ p = AliasHandleName(p, pmax); /* Destination Name */
+ break;
+ case DGM_ERROR:
+ p = (u_char *) ndh + 11;
+ break;
+ case DGM_QUERY:
+ case DGM_POSITIVE_RES:
+ case DGM_NEGATIVE_RES:
+ p = (u_char *) ndh + 10;
+ p = AliasHandleName(p, pmax); /* Destination Name */
+ break;
}
- if (p == NULL || (char *)p > pmax)
- p = NULL;
+ if (p == NULL || (char *)p > pmax)
+ p = NULL;
#ifdef DEBUG
- printf("%s:%d-->", inet_ntoa(ndh->source_ip), ntohs(ndh->source_port) );
+ printf("%s:%d-->", inet_ntoa(ndh->source_ip), ntohs(ndh->source_port));
#endif
/* Doing an IP address and Port number Translation */
- if ( uh->uh_sum != 0 ) {
- int acc;
- u_short *sptr;
- acc = ndh->source_port;
+ if (uh->uh_sum != 0) {
+ int acc;
+ u_short *sptr;
+
+ acc = ndh->source_port;
acc -= alias_port;
- sptr = (u_short *) &(ndh->source_ip);
+ sptr = (u_short *) & (ndh->source_ip);
acc += *sptr++;
acc += *sptr;
sptr = (u_short *) alias_address;
@@ -254,49 +262,49 @@ int AliasHandleUdpNbt(
acc -= *sptr;
ADJUST_CHECKSUM(acc, uh->uh_sum);
}
- ndh->source_ip = *alias_address;
- ndh->source_port = alias_port;
+ ndh->source_ip = *alias_address;
+ ndh->source_port = alias_port;
#ifdef DEBUG
- printf("%s:%d\n", inet_ntoa(ndh->source_ip), ntohs(ndh->source_port) );
+ printf("%s:%d\n", inet_ntoa(ndh->source_ip), ntohs(ndh->source_port));
fflush(stdout);
#endif
- return((p == NULL) ? -1 : 0);
+ return ((p == NULL) ? -1 : 0);
}
+
/* Question Section */
#define QS_TYPE_NB 0x0020
#define QS_TYPE_NBSTAT 0x0021
#define QS_CLAS_IN 0x0001
typedef struct {
- u_short type; /* The type of Request */
- u_short class; /* The class of Request */
-} NBTNsQuestion;
+ u_short type; /* The type of Request */
+ u_short class; /* The class of Request */
+} NBTNsQuestion;
-static u_char *
+static u_char *
AliasHandleQuestion(
u_short count,
- NBTNsQuestion *q,
+ NBTNsQuestion * q,
char *pmax,
- NBTArguments *nbtarg)
+ NBTArguments * nbtarg)
{
- while ( count != 0 ) {
+ while (count != 0) {
/* Name Filed */
- q = (NBTNsQuestion *)AliasHandleName((u_char *)q, pmax);
+ q = (NBTNsQuestion *) AliasHandleName((u_char *) q, pmax);
if (q == NULL || (char *)(q + 1) > pmax) {
q = NULL;
break;
}
-
/* Type and Class filed */
- switch ( ntohs(q->type) ) {
- case QS_TYPE_NB:
- case QS_TYPE_NBSTAT:
- q= q+1;
+ switch (ntohs(q->type)) {
+ case QS_TYPE_NB:
+ case QS_TYPE_NBSTAT:
+ q = q + 1;
break;
- default:
+ default:
#ifdef DEBUG
- printf("\nUnknown Type on Question %0x\n", ntohs(q->type) );
+ printf("\nUnknown Type on Question %0x\n", ntohs(q->type));
#endif
break;
}
@@ -304,7 +312,7 @@ AliasHandleQuestion(
}
/* Set up to out of Question Section */
- return ((u_char *)q);
+ return ((u_char *) q);
}
/* Resource Record */
@@ -316,101 +324,99 @@ AliasHandleQuestion(
#define RR_CLAS_IN 0x0001
#define SizeOfNsResource 8
typedef struct {
- u_short type;
- u_short class;
- unsigned int ttl;
- u_short rdlen;
-} NBTNsResource;
+ u_short type;
+ u_short class;
+ unsigned int ttl;
+ u_short rdlen;
+} NBTNsResource;
#define SizeOfNsRNB 6
typedef struct {
- u_short g:1, ont:2, resv:13;
- struct in_addr addr;
-} NBTNsRNB;
+ u_short g: 1 , ont:2, resv:13;
+ struct in_addr addr;
+} NBTNsRNB;
-static u_char *
+static u_char *
AliasHandleResourceNB(
- NBTNsResource *q,
+ NBTNsResource * q,
char *pmax,
- NBTArguments *nbtarg)
+ NBTArguments * nbtarg)
{
- NBTNsRNB *nb;
+ NBTNsRNB *nb;
u_short bcount;
if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
+ return (NULL);
/* Check out a length */
bcount = ntohs(q->rdlen);
/* Forward to Resource NB position */
- nb = (NBTNsRNB *)((u_char *)q + SizeOfNsResource);
+ nb = (NBTNsRNB *) ((u_char *) q + SizeOfNsResource);
/* Processing all in_addr array */
#ifdef DEBUG
printf("NB rec[%s", inet_ntoa(nbtarg->oldaddr));
- printf("->%s, %dbytes] ",inet_ntoa(nbtarg->newaddr ), bcount);
+ printf("->%s, %dbytes] ", inet_ntoa(nbtarg->newaddr), bcount);
#endif
- while ( nb != NULL && bcount != 0 ) {
+ while (nb != NULL && bcount != 0) {
if ((char *)(nb + 1) > pmax) {
nb = NULL;
break;
}
#ifdef DEBUG
- printf("<%s>", inet_ntoa(nb->addr) );
+ printf("<%s>", inet_ntoa(nb->addr));
#endif
- if (!bcmp(&nbtarg->oldaddr,&nb->addr, sizeof(struct in_addr) ) ) {
- if ( *nbtarg->uh_sum != 0 ) {
- int acc;
- u_short *sptr;
-
- sptr = (u_short *) &(nb->addr);
- acc = *sptr++;
- acc += *sptr;
- sptr = (u_short *) &(nbtarg->newaddr);
- acc -= *sptr++;
- acc -= *sptr;
- ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
+ if (!bcmp(&nbtarg->oldaddr, &nb->addr, sizeof(struct in_addr))) {
+ if (*nbtarg->uh_sum != 0) {
+ int acc;
+ u_short *sptr;
+
+ sptr = (u_short *) & (nb->addr);
+ acc = *sptr++;
+ acc += *sptr;
+ sptr = (u_short *) & (nbtarg->newaddr);
+ acc -= *sptr++;
+ acc -= *sptr;
+ ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
}
-
nb->addr = nbtarg->newaddr;
#ifdef DEBUG
printf("O");
#endif
}
#ifdef DEBUG
- else {
+ else {
printf(".");
}
#endif
- nb=(NBTNsRNB *)((u_char *)nb + SizeOfNsRNB);
- bcount -= SizeOfNsRNB;
+ nb = (NBTNsRNB *) ((u_char *) nb + SizeOfNsRNB);
+ bcount -= SizeOfNsRNB;
}
if (nb == NULL || (char *)(nb + 1) > pmax) {
nb = NULL;
}
-
- return ((u_char *)nb);
+ return ((u_char *) nb);
}
#define SizeOfResourceA 6
typedef struct {
- struct in_addr addr;
-} NBTNsResourceA;
+ struct in_addr addr;
+} NBTNsResourceA;
-static u_char *
+static u_char *
AliasHandleResourceA(
- NBTNsResource *q,
+ NBTNsResource * q,
char *pmax,
- NBTArguments *nbtarg)
+ NBTArguments * nbtarg)
{
- NBTNsResourceA *a;
+ NBTNsResourceA *a;
u_short bcount;
if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
+ return (NULL);
/* Forward to Resource A position */
- a = (NBTNsResourceA *)( (u_char *)q + sizeof(NBTNsResource) );
+ a = (NBTNsResourceA *) ((u_char *) q + sizeof(NBTNsResource));
/* Check out of length */
bcount = ntohs(q->rdlen);
@@ -418,62 +424,61 @@ AliasHandleResourceA(
/* Processing all in_addr array */
#ifdef DEBUG
printf("Arec [%s", inet_ntoa(nbtarg->oldaddr));
- printf("->%s]",inet_ntoa(nbtarg->newaddr ));
+ printf("->%s]", inet_ntoa(nbtarg->newaddr));
#endif
- while ( bcount != 0 ) {
+ while (bcount != 0) {
if (a == NULL || (char *)(a + 1) > pmax)
- return(NULL);
+ return (NULL);
#ifdef DEBUG
- printf("..%s", inet_ntoa(a->addr) );
+ printf("..%s", inet_ntoa(a->addr));
#endif
- if ( !bcmp(&nbtarg->oldaddr, &a->addr, sizeof(struct in_addr) ) ) {
- if ( *nbtarg->uh_sum != 0 ) {
- int acc;
- u_short *sptr;
-
- sptr = (u_short *) &(a->addr); /* Old */
- acc = *sptr++;
- acc += *sptr;
- sptr = (u_short *) &nbtarg->newaddr; /* New */
- acc -= *sptr++;
- acc -= *sptr;
- ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
+ if (!bcmp(&nbtarg->oldaddr, &a->addr, sizeof(struct in_addr))) {
+ if (*nbtarg->uh_sum != 0) {
+ int acc;
+ u_short *sptr;
+
+ sptr = (u_short *) & (a->addr); /* Old */
+ acc = *sptr++;
+ acc += *sptr;
+ sptr = (u_short *) & nbtarg->newaddr; /* New */
+ acc -= *sptr++;
+ acc -= *sptr;
+ ADJUST_CHECKSUM(acc, *nbtarg->uh_sum);
}
-
a->addr = nbtarg->newaddr;
}
- a++; /*XXXX*/
+ a++; /* XXXX */
bcount -= SizeOfResourceA;
}
if (a == NULL || (char *)(a + 1) > pmax)
- a = NULL;
- return ((u_char *)a);
+ a = NULL;
+ return ((u_char *) a);
}
typedef struct {
- u_short opcode:4, flags:8, resv:4;
-} NBTNsResourceNULL;
+ u_short opcode:4, flags:8, resv:4;
+} NBTNsResourceNULL;
-static u_char *
+static u_char *
AliasHandleResourceNULL(
- NBTNsResource *q,
+ NBTNsResource * q,
char *pmax,
- NBTArguments *nbtarg)
+ NBTArguments * nbtarg)
{
- NBTNsResourceNULL *n;
+ NBTNsResourceNULL *n;
u_short bcount;
if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
+ return (NULL);
/* Forward to Resource NULL position */
- n = (NBTNsResourceNULL *)( (u_char *)q + sizeof(NBTNsResource) );
+ n = (NBTNsResourceNULL *) ((u_char *) q + sizeof(NBTNsResource));
/* Check out of length */
bcount = ntohs(q->rdlen);
/* Processing all in_addr array */
- while ( bcount != 0 ) {
+ while (bcount != 0) {
if ((char *)(n + 1) > pmax) {
n = NULL;
break;
@@ -484,223 +489,220 @@ AliasHandleResourceNULL(
if ((char *)(n + 1) > pmax)
n = NULL;
- return ((u_char *)n);
+ return ((u_char *) n);
}
-static u_char *
+static u_char *
AliasHandleResourceNS(
- NBTNsResource *q,
+ NBTNsResource * q,
char *pmax,
- NBTArguments *nbtarg)
+ NBTArguments * nbtarg)
{
- NBTNsResourceNULL *n;
+ NBTNsResourceNULL *n;
u_short bcount;
if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
+ return (NULL);
/* Forward to Resource NULL position */
- n = (NBTNsResourceNULL *)( (u_char *)q + sizeof(NBTNsResource) );
+ n = (NBTNsResourceNULL *) ((u_char *) q + sizeof(NBTNsResource));
/* Check out of length */
bcount = ntohs(q->rdlen);
/* Resource Record Name Filed */
- q = (NBTNsResource *)AliasHandleName( (u_char *)n, pmax ); /* XXX */
+ q = (NBTNsResource *) AliasHandleName((u_char *) n, pmax); /* XXX */
- if (q == NULL || (char *)((u_char *)n + bcount) > pmax)
- return(NULL);
+ if (q == NULL || (char *)((u_char *) n + bcount) > pmax)
+ return (NULL);
else
- return ((u_char *)n + bcount);
+ return ((u_char *) n + bcount);
}
typedef struct {
- u_short numnames;
-} NBTNsResourceNBSTAT;
+ u_short numnames;
+} NBTNsResourceNBSTAT;
-static u_char *
+static u_char *
AliasHandleResourceNBSTAT(
- NBTNsResource *q,
+ NBTNsResource * q,
char *pmax,
- NBTArguments *nbtarg)
+ NBTArguments * nbtarg)
{
- NBTNsResourceNBSTAT *n;
+ NBTNsResourceNBSTAT *n;
u_short bcount;
if (q == NULL || (char *)(q + 1) > pmax)
- return(NULL);
+ return (NULL);
/* Forward to Resource NBSTAT position */
- n = (NBTNsResourceNBSTAT *)( (u_char *)q + sizeof(NBTNsResource) );
+ n = (NBTNsResourceNBSTAT *) ((u_char *) q + sizeof(NBTNsResource));
/* Check out of length */
bcount = ntohs(q->rdlen);
- if (q == NULL || (char *)((u_char *)n + bcount) > pmax)
- return(NULL);
+ if (q == NULL || (char *)((u_char *) n + bcount) > pmax)
+ return (NULL);
else
- return ((u_char *)n + bcount);
+ return ((u_char *) n + bcount);
}
-static u_char *
+static u_char *
AliasHandleResource(
u_short count,
- NBTNsResource *q,
+ NBTNsResource * q,
char *pmax,
NBTArguments
- *nbtarg)
+ * nbtarg)
{
- while ( count != 0 ) {
+ while (count != 0) {
/* Resource Record Name Filed */
- q = (NBTNsResource *)AliasHandleName( (u_char *)q, pmax );
+ q = (NBTNsResource *) AliasHandleName((u_char *) q, pmax);
if (q == NULL || (char *)(q + 1) > pmax)
break;
#ifdef DEBUG
- printf("type=%02x, count=%d\n", ntohs(q->type), count );
+ printf("type=%02x, count=%d\n", ntohs(q->type), count);
#endif
/* Type and Class filed */
- switch ( ntohs(q->type) ) {
- case RR_TYPE_NB:
- q = (NBTNsResource *)AliasHandleResourceNB(
- q,
- pmax,
- nbtarg
- );
- break;
- case RR_TYPE_A:
- q = (NBTNsResource *)AliasHandleResourceA(
- q,
- pmax,
- nbtarg
- );
- break;
- case RR_TYPE_NS:
- q = (NBTNsResource *)AliasHandleResourceNS(
- q,
- pmax,
- nbtarg
- );
- break;
- case RR_TYPE_NULL:
- q = (NBTNsResource *)AliasHandleResourceNULL(
- q,
- pmax,
- nbtarg
- );
- break;
- case RR_TYPE_NBSTAT:
- q = (NBTNsResource *)AliasHandleResourceNBSTAT(
- q,
- pmax,
- nbtarg
- );
- break;
- default:
+ switch (ntohs(q->type)) {
+ case RR_TYPE_NB:
+ q = (NBTNsResource *) AliasHandleResourceNB(
+ q,
+ pmax,
+ nbtarg
+ );
+ break;
+ case RR_TYPE_A:
+ q = (NBTNsResource *) AliasHandleResourceA(
+ q,
+ pmax,
+ nbtarg
+ );
+ break;
+ case RR_TYPE_NS:
+ q = (NBTNsResource *) AliasHandleResourceNS(
+ q,
+ pmax,
+ nbtarg
+ );
+ break;
+ case RR_TYPE_NULL:
+ q = (NBTNsResource *) AliasHandleResourceNULL(
+ q,
+ pmax,
+ nbtarg
+ );
+ break;
+ case RR_TYPE_NBSTAT:
+ q = (NBTNsResource *) AliasHandleResourceNBSTAT(
+ q,
+ pmax,
+ nbtarg
+ );
+ break;
+ default:
#ifdef DEBUG
- printf(
- "\nUnknown Type of Resource %0x\n",
- ntohs(q->type)
- );
+ printf(
+ "\nUnknown Type of Resource %0x\n",
+ ntohs(q->type)
+ );
#endif
- break;
+ break;
}
count--;
}
fflush(stdout);
- return ((u_char *)q);
+ return ((u_char *) q);
}
-int AliasHandleUdpNbtNS(
- struct libalias *la,
- struct ip *pip, /* IP packet to examine/patch */
- struct alias_link *link,
- struct in_addr *alias_address,
- u_short *alias_port,
- struct in_addr *original_address,
- u_short *original_port )
+int
+AliasHandleUdpNbtNS(
+ struct libalias *la,
+ struct ip *pip, /* IP packet to examine/patch */
+ struct alias_link *link,
+ struct in_addr *alias_address,
+ u_short * alias_port,
+ struct in_addr *original_address,
+ u_short * original_port)
{
- struct udphdr * uh;
- NbtNSHeader * nsh;
- u_char * p;
- char *pmax;
- NBTArguments nbtarg;
+ struct udphdr *uh;
+ NbtNSHeader *nsh;
+ u_char *p;
+ char *pmax;
+ NBTArguments nbtarg;
/* Set up Common Parameter */
- nbtarg.oldaddr = *alias_address;
- nbtarg.oldport = *alias_port;
- nbtarg.newaddr = *original_address;
- nbtarg.newport = *original_port;
+ nbtarg.oldaddr = *alias_address;
+ nbtarg.oldport = *alias_port;
+ nbtarg.newaddr = *original_address;
+ nbtarg.newport = *original_port;
- /* Calculate data length of UDP packet */
- uh = (struct udphdr *) ((char *) pip + (pip->ip_hl << 2));
- nbtarg.uh_sum = &(uh->uh_sum);
- nsh = (NbtNSHeader *)((char *)uh + (sizeof(struct udphdr)));
- p = (u_char *)(nsh + 1);
- pmax = (char *)uh + ntohs( uh->uh_ulen );
+ /* Calculate data length of UDP packet */
+ uh = (struct udphdr *)((char *)pip + (pip->ip_hl << 2));
+ nbtarg.uh_sum = &(uh->uh_sum);
+ nsh = (NbtNSHeader *) ((char *)uh + (sizeof(struct udphdr)));
+ p = (u_char *) (nsh + 1);
+ pmax = (char *)uh + ntohs(uh->uh_ulen);
- if ((char *)(nsh + 1) > pmax)
- return(-1);
+ if ((char *)(nsh + 1) > pmax)
+ return (-1);
#ifdef DEBUG
- printf(" [%s] ID=%02x, op=%01x, flag=%02x, rcode=%01x, qd=%04x"
- ", an=%04x, ns=%04x, ar=%04x, [%d]-->",
- nsh->dir ? "Response": "Request",
- nsh->nametrid,
- nsh->opcode,
- nsh->nmflags,
- nsh->rcode,
- ntohs(nsh->qdcount),
- ntohs(nsh->ancount),
- ntohs(nsh->nscount),
- ntohs(nsh->arcount),
- (u_char *)p -(u_char *)nsh
- );
+ printf(" [%s] ID=%02x, op=%01x, flag=%02x, rcode=%01x, qd=%04x"
+ ", an=%04x, ns=%04x, ar=%04x, [%d]-->",
+ nsh->dir ? "Response" : "Request",
+ nsh->nametrid,
+ nsh->opcode,
+ nsh->nmflags,
+ nsh->rcode,
+ ntohs(nsh->qdcount),
+ ntohs(nsh->ancount),
+ ntohs(nsh->nscount),
+ ntohs(nsh->arcount),
+ (u_char *) p - (u_char *) nsh
+ );
#endif
/* Question Entries */
- if (ntohs(nsh->qdcount) !=0 ) {
- p = AliasHandleQuestion(
- ntohs(nsh->qdcount),
- (NBTNsQuestion *)p,
- pmax,
- &nbtarg
- );
+ if (ntohs(nsh->qdcount) != 0) {
+ p = AliasHandleQuestion(
+ ntohs(nsh->qdcount),
+ (NBTNsQuestion *) p,
+ pmax,
+ &nbtarg
+ );
}
-
/* Answer Resource Records */
- if (ntohs(nsh->ancount) !=0 ) {
- p = AliasHandleResource(
- ntohs(nsh->ancount),
- (NBTNsResource *)p,
- pmax,
- &nbtarg
- );
+ if (ntohs(nsh->ancount) != 0) {
+ p = AliasHandleResource(
+ ntohs(nsh->ancount),
+ (NBTNsResource *) p,
+ pmax,
+ &nbtarg
+ );
}
-
/* Authority Resource Recodrs */
- if (ntohs(nsh->nscount) !=0 ) {
- p = AliasHandleResource(
- ntohs(nsh->nscount),
- (NBTNsResource *)p,
- pmax,
- &nbtarg
- );
+ if (ntohs(nsh->nscount) != 0) {
+ p = AliasHandleResource(
+ ntohs(nsh->nscount),
+ (NBTNsResource *) p,
+ pmax,
+ &nbtarg
+ );
}
-
/* Additional Resource Recodrs */
- if (ntohs(nsh->arcount) !=0 ) {
- p = AliasHandleResource(
- ntohs(nsh->arcount),
- (NBTNsResource *)p,
- pmax,
- &nbtarg
- );
+ if (ntohs(nsh->arcount) != 0) {
+ p = AliasHandleResource(
+ ntohs(nsh->arcount),
+ (NBTNsResource *) p,
+ pmax,
+ &nbtarg
+ );
}
-
#ifdef DEBUG
- PrintRcode(nsh->rcode);
+ PrintRcode(nsh->rcode);
#endif
- return ((p == NULL) ? -1 : 0);
+ return ((p == NULL) ? -1 : 0);
}
OpenPOWER on IntegriCloud