49#include <sys/kernel.h>
50#include <sys/module.h>
71#define NETBIOS_NS_PORT_NUMBER 137
72#define NETBIOS_DGM_PORT_NUMBER 138
84 if (ah->
dport == NULL || ah->
sport == NULL || ah->
lnk == NULL ||
102 if (ah->
dport == NULL || ah->
sport == NULL || ah->
lnk == NULL ||
211 u_short
dir:1, opcode:4, nmflags:7, rcode:4;
227PrintRcode(u_char rcode)
231 printf(
"\nFormat Error.");
233 printf(
"\nSever failure.");
235 printf(
"\nUnsupported request error.\n");
237 printf(
"\nRefused error.\n");
239 printf(
"\nActive error.\n");
241 printf(
"\nName in conflict error.\n");
243 printf(
"\n?%c?=%0x\n",
'?', rcode);
259 if (p == NULL || (
char *)p >= pmax)
264 if ((
char *)p > pmax)
266 return ((u_char *)p);
268 while ((*p & 0x3f) != 0x00) {
276 p = (u_char *)(p + (*p & 0x3f) + 1);
277 if ((
char *)p > pmax) {
286 c = (u_char) (((((*s & 0x0f) << 4) | (*(s + 1) & 0x0f)) - 0x11));
291 printf(
"<0x%02x>", c);
308 if (p == NULL || (
char *)p >= pmax)
312 return ((u_char *)p);
318#define DGM_DIRECT_UNIQ 0x10
319#define DGM_DIRECT_GROUP 0x11
320#define DGM_BROADCAST 0x12
321#define DGM_ERROR 0x13
322#define DGM_QUERY 0x14
323#define DGM_POSITIVE_RES 0x15
324#define DGM_NEGATIVE_RES 0x16
339 char addrbuf[INET_ADDRSTRLEN];
346 uh = (
struct udphdr *)ip_next(pip);
347 pmax = (
char *)uh + ntohs(uh->
uh_ulen);
350 if ((
char *)(ndh + 1) > pmax)
353 printf(
"\nType=%02x,", ndh->
type);
359 p = (u_char *)ndh + 14;
364 p = (u_char *)ndh + 11;
369 p = (u_char *)ndh + 10;
373 if (p == NULL || (
char *)p > pmax)
389 sptr = (u_short *)alias_address;
401 return ((p == NULL) ? -1 : 0);
405#define QS_TYPE_NB 0x0020
406#define QS_TYPE_NBSTAT 0x0021
407#define QS_CLAS_IN 0x0001
426 if (q == NULL || (
char *)(q + 1) > pmax) {
431 switch (ntohs(q->
type)) {
438 printf(
"\nUnknown Type on Question %0x\n", ntohs(q->
type));
446 return ((u_char *)q);
450#define RR_TYPE_A 0x0001
451#define RR_TYPE_NS 0x0002
452#define RR_TYPE_NULL 0x000a
453#define RR_TYPE_NB 0x0020
454#define RR_TYPE_NBSTAT 0x0021
455#define RR_CLAS_IN 0x0001
456#define SizeOfNsResource 8
466 u_short
g:1, ont:2, resv:13;
479 char oldbuf[INET_ADDRSTRLEN];
480 char newbuf[INET_ADDRSTRLEN];
483 if (q == NULL || (
char *)(q + 1) > pmax)
486 bcount = ntohs(q->
rdlen);
493 printf(
"NB rec[%s->%s, %dbytes] ",
498 while (nb != NULL && bcount != 0) {
499 if ((
char *)(nb + 1) > pmax) {
507 if (*nbtarg->
uh_sum != 0) {
511 sptr = (u_short *)&(nb->
addr);
514 sptr = (u_short *)&(nbtarg->
newaddr);
532 if (nb == NULL || (
char *)(nb + 1) > pmax) {
535 return ((u_char *)nb);
538#define SizeOfResourceA 6
552 char oldbuf[INET_ADDRSTRLEN];
553 char newbuf[INET_ADDRSTRLEN];
556 if (q == NULL || (
char *)(q + 1) > pmax)
563 bcount = ntohs(q->
rdlen);
567 printf(
"Arec [%s->%s]",
571 while (bcount != 0) {
572 if (a == NULL || (
char *)(a + 1) > pmax)
578 if (*nbtarg->
uh_sum != 0) {
582 sptr = (u_short *)&(a->
addr);
585 sptr = (u_short *)&nbtarg->
newaddr;
595 if (a == NULL || (
char *)(a + 1) > pmax)
597 return ((u_char *)a);
615 if (q == NULL || (
char *)(q + 1) > pmax)
622 bcount = ntohs(q->
rdlen);
625 while (bcount != 0) {
626 if ((
char *)(n + 1) > pmax) {
633 if ((
char *)(n + 1) > pmax)
636 return ((u_char *)n);
650 if (q == NULL || (
char *)(q + 1) > pmax)
657 bcount = ntohs(q->
rdlen);
662 if (q == NULL || (
char *)((u_char *)n + bcount) > pmax)
665 return ((u_char *)n + bcount);
683 if (q == NULL || (
char *)(q + 1) > pmax)
690 bcount = ntohs(q->
rdlen);
692 if (q == NULL || (
char *)((u_char *)n + bcount) > pmax)
695 return ((u_char *)n + bcount);
709 if (q == NULL || (
char *)(q + 1) > pmax)
712 printf(
"type=%02x, count=%d\n", ntohs(q->
type),
count);
716 switch (ntohs(q->
type)) {
740 "\nUnknown Type of Resource %0x\n",
749 return ((u_char *)q);
759 struct in_addr *original_address,
760 u_short *original_port)
772 nbtarg.
oldaddr = *alias_address;
774 nbtarg.
newaddr = *original_address;
775 nbtarg.
newport = *original_port;
778 uh = (
struct udphdr *)ip_next(pip);
781 p = (u_char *)(nsh + 1);
782 pmax = (
char *)uh + ntohs(uh->
uh_ulen);
784 if ((
char *)(nsh + 1) > pmax)
788 printf(
" [%s] ID=%02x, op=%01x, flag=%02x, rcode=%01x, qd=%04x"
789 ", an=%04x, ns=%04x, ar=%04x, [%d]-->",
790 nsh->
dir ?
"Response" :
"Request",
799 (u_char *)p - (u_char *)nsh
804 if (ntohs(nsh->
qdcount) != 0) {
813 if (ntohs(nsh->
ancount) != 0) {
822 if (ntohs(nsh->
nscount) != 0) {
831 if (ntohs(nsh->
arcount) != 0) {
840 PrintRcode(nsh->
rcode);
842 return ((p == NULL) ? -1 : 0);
#define INET_NTOA_BUF(buf)
#define ADJUST_CHECKSUM(acc, cksum)
int LibAliasAttachHandlers(struct proto_handler *p)
int LibAliasDetachHandlers(struct proto_handler *p)
static int AliasHandleUdpNbt(struct libalias *, struct ip *, struct alias_link *, struct in_addr *, u_short)
static int mod_handler(module_t mod, int type, void *data)
MODULE_DEPEND(alias_nbt, libalias, 1, 1, 1)
#define NETBIOS_NS_PORT_NUMBER
static u_char * AliasHandleResourceNS(NBTNsResource *q, char *pmax, NBTArguments *nbtarg)
DECLARE_MODULE(alias_nbt, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND)
static u_char * AliasHandleName(u_char *p, char *pmax)
static u_char * AliasHandleResource(u_short count, NBTNsResource *q, char *pmax, NBTArguments *nbtarg)
static u_char * AliasHandleResourceNB(NBTNsResource *q, char *pmax, NBTArguments *nbtarg)
static moduledata_t alias_mod
static int fingerprint2(struct libalias *la, struct alias_data *ah)
static u_char * AliasHandleQuestion(u_short count, NBTNsQuestion *q, char *pmax, NBTArguments *nbtarg)
static u_char * AliasHandleResourceA(NBTNsResource *q, char *pmax, NBTArguments *nbtarg)
static u_char * AliasHandleResourceNBSTAT(NBTNsResource *q, char *pmax, NBTArguments *nbtarg)
static int protohandler2in(struct libalias *la, struct ip *pip, struct alias_data *ah)
#define NETBIOS_DGM_PORT_NUMBER
static int protohandler1(struct libalias *la, struct ip *pip, struct alias_data *ah)
static u_char * AliasHandleResourceNULL(NBTNsResource *q, char *pmax, NBTArguments *nbtarg)
static int fingerprint1(struct libalias *la, struct alias_data *ah)
struct proto_handler handlers[]
MODULE_VERSION(alias_nbt, 1)
static int AliasHandleUdpNbtNS(struct libalias *, struct ip *, struct alias_link *, struct in_addr *, u_short *, struct in_addr *, u_short *)
static int protohandler2out(struct libalias *la, struct ip *pip, struct alias_data *ah)
char * inet_ntoa_r(struct in_addr ina, char *buf)