📄 _w3ng.c
字号:
/*
* Copyright (c) 1992, 1993, 1994, 1995, 1996
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#if 0
static const char rcsid[] =
"@(#) $Header: /ng/src/proto-analyser/tcpdump/RCS/print-w3ng.c,v 1.4 1998/06/25 07:27:49 janssen Exp $ (LBL)";
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <ctype.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
#include "interfac.h"
#include "a2name.h"
#define W3NG_CONTROL_MSG_P(x) (((x)&0x80000000)!=0)
#define W3NG_CONTROL_MSG_ID(x) (((x)&0x70000000)>>28)
#define W3NG_EXTENSION_HEADERS_P(x) (((x)&0x40000000)!=0)
#define W3NG_REQUEST_DISC_CACHED_P(x) (((x)&0x00004000)!=0)
#define W3NG_REQUEST_DISC_CACHE_IDX(x) ((x) &0x00003FFF)
#define W3NG_REQUEST_CACHE_DISC_P(x) (((x)&0x00002000)!=0)
#define W3NG_REQUEST_DISC_LEN(x) ((x) &0x00001FFF)
#define W3NG_REQUEST_OP_CACHED_P(x) (((x)&0x20000000)!=0)
#define W3NG_REQUEST_OP_CACHE_IDX(x) (((x)&0x1FFF8000)>>15)
#define W3NG_REQUEST_CACHE_OP_P(x) (((x)&0x10000000)!=0)
#define W3NG_REQUEST_OP_INDEX(x) (((x)&0x0FFF8000)>>15)
#define W3NG_REPLY_STATUS(x) (((x)&0x30000000)>>28)
#define W3NG_REPLY_SERIAL_NUMBER(x) ((x)&0x00FFFFFF)
#define W3NG_INITIALIZE_CONNECTION_MSG 0
#define W3NG_TERMINATE_CONNECTION_MSG 1
#define W3NG_DEFAULT_CHARSET_MSG 2
#define W3NG_INITIALIZE_CONNECTION_SIDLEN(x) ((x)&0x0000FFFF)
#define W3NG_INITIALIZE_CONNECTION_VERSION_H(x) (((x)&0x00F00000)>>20)
#define W3NG_INITIALIZE_CONNECTION_VERSION_L(x) (((x)&0x000F0000)>>16)
#define W3NG_TERMINATE_CONNECTION_CAUSE(x) (((x)&0x0F000000)>>24)
#define W3NG_TERMINATE_CONNECTION_LAST_SN(x) ((x)&0x00FFFFFF)
#define W3NG_DEFAULT_CHARSET_CHARSET(x) ((x)&0x0000FFFF)
#define W3NG_REPLY_STATUS_SUCCESS 0
#define W3NG_REPLY_STATUS_USEREXN 1
#define W3NG_REPLY_STATUS_SYSEXNB 2
#define W3NG_REPLY_STATUS_SYSEXNA 3
/* System Exceptions
*/
#define W3NG_SYSEXN_UnknownProblem 0
#define W3NG_SYSEXN_ImplementationLimit 1
#define W3NG_SYSEXN_SwitchSessionCinfo 2
#define W3NG_SYSEXN_Marshal 3
#define W3NG_SYSEXN_NoSuchObjectType 4
#define W3NG_SYSEXN_NoSuchMethod 5
#define W3NG_SYSEXN_Rejected 6
#define W3NG_SYSEXN_DiscOrOpCacheOverflow 7
struct op_cache_entry {
u_int cache_index;
u_char *typeid;
u_int typeidlen;
u_int index;
};
struct op_cache_array {
struct op_cache_entry *entries;
u_int size;
u_int used;
};
struct disc_cache_entry {
u_int cache_index;
u_char *ih;
u_int ihlen;
};
struct disc_cache_array {
struct disc_cache_entry *entries;
u_int size;
u_int used;
};
struct w3ng_state {
u_int id; /* connection id */
u_int caller; /* non-zero if InitializeConnection has been seen */
u_int serial_number; /* counter for generation of serial #'s */
struct op_cache_array op_cache;
struct disc_cache_array disc_cache;
};
struct state_list {
struct state_list *next;
struct w3ng_state state;
};
static struct state_list *connections = NULL;
static __inline struct w3ng_state *add_state (u_int id)
{
struct state_list *newstate = calloc (sizeof(*newstate), 1);
if (!newstate)
return (NULL);
newstate->state.id = id;
newstate->next = connections;
connections = newstate;
return (&newstate->state);
}
static __inline struct w3ng_state *find_state (u_int id)
{
struct state_list *p;
for (p = connections; p; p = p->next)
{
if (p->state.id == id)
return (&p->state);
}
return (NULL);
}
static void cache_operation (struct w3ng_state *s, u_char *typeid,
u_int typeidlen, u_int index)
{
if (s->op_cache.used >= s->op_cache.size)
{
if (s->op_cache.entries == 0)
{
s->op_cache.entries = malloc (sizeof(struct op_cache_entry) * 2);
s->op_cache.size = 2;
}
else
{
s->op_cache.entries = realloc (s->op_cache.entries,
sizeof(struct op_cache_entry) *
2 * s->op_cache.size);
s->op_cache.size = 2 * s->op_cache.size;
}
}
s->op_cache.entries[s->op_cache.used].typeid = malloc (typeidlen + 1);
memcpy (s->op_cache.entries[s->op_cache.used].typeid, typeid, typeidlen);
s->op_cache.entries[s->op_cache.used].typeid[typeidlen] = 0;
s->op_cache.entries[s->op_cache.used].typeidlen = typeidlen;
s->op_cache.entries[s->op_cache.used].index = index;
s->op_cache.used += 1;
}
static u_int get_cached_operation (struct w3ng_state *s, u_int cache_index,
u_char **typeid, u_int *typeidlen,
u_int *index)
{
if (s->op_cache.used <= cache_index)
return (0);
*typeid = s->op_cache.entries[cache_index].typeid;
*typeidlen = s->op_cache.entries[cache_index].typeidlen;
*index = s->op_cache.entries[cache_index].index;
return (1);
}
static void cache_discriminant (struct w3ng_state *s, u_char *ih, u_int ihlen)
{
if (s->disc_cache.used >= s->disc_cache.size)
{
if (s->disc_cache.entries == 0)
{
s->disc_cache.entries = malloc (sizeof(struct disc_cache_entry) * 2);
s->disc_cache.size = 2;
}
else
{
s->disc_cache.entries = realloc (s->disc_cache.entries,
sizeof(struct disc_cache_entry) * 2 *
s->disc_cache.size);
s->disc_cache.size = 2 * s->disc_cache.size;
}
}
s->disc_cache.entries[s->disc_cache.used].ih = malloc (ihlen + 1);
memcpy (s->disc_cache.entries[s->disc_cache.used].ih, ih, ihlen);
s->disc_cache.entries[s->disc_cache.used].ih[ihlen] = 0;
s->disc_cache.entries[s->disc_cache.used].ihlen = ihlen;
s->disc_cache.used += 1;
}
static u_int get_cached_discriminant (struct w3ng_state *s,
u_int cache_index, u_char **ih,
u_int *ihlen)
{
if (s->disc_cache.used <= cache_index)
return (0);
*ih = s->disc_cache.entries[cache_index].ih;
*ihlen = s->disc_cache.entries[cache_index].ihlen;
return (1);
}
static char *quote_chars (u_char *p, u_int len)
{
char *n;
u_int i;
n = malloc (len + 1);
if (!n)
return (NULL);
for (i = 0; i < len; i++)
{
if (!isgraph ((int) (p[i])))
n[i] = '.';
else n[i] = (char) p[i];
}
n[len] = '\0';
return (n);
}
void w3ng_print (u_int connection, const u_char *msg, u_int msglen)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -