📄 _giop2.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-giop.c,v 1.7 1998/06/28 03:12:43 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 IIOP_TAG_INTERNET_IOP 0
#define IIOP_TAG_MULTIPLE_COMPONENT_IOP 1
#define IIOP_TAG_ILU_IOP 0x494c5500
#define IIOP_TAG_ILU_SUNRPC_IOP 0x494c5501
#define IIOP_TAG_ILU_COURIER_IOP 0x494c5502
#define IIOP_TAG_ILU_UNUSED1_IOP 0x494c5503
#define IIOP_TAG_ILU_UNUSED2_IOP 0x494c5504
#define IIOP_TAG_ILU_UNUSED3_IOP 0x494c5505
#define IIOP_TAG_ILU_UNUSED4_IOP 0x494c5506
#define IIOP_TAG_ILU_UNUSED5_IOP 0x494c5507
#define IIOP_TAG_CODE_SETS 1
#define IIOP_CHARSET_UNICODE_1_1 0x00010100
#define IIOP_CHARSET_UNICODE_UTF_8 0x05010001
#define IIOP_CHARSET_ISO_LATIN1 0x00010001
#define IIOP_CHARSET_US_ASCII 0x00010020
#define GIOP_MSGTYPE_REQUEST 0
#define GIOP_MSGTYPE_REPLY 1
#define GIOP_MSGTYPE_CANCEL_REQUEST 2
#define GIOP_MSGTYPE_LOCATE_REQUEST 3
#define GIOP_MSGTYPE_LOCATE_REPLY 4
#define GIOP_MSGTYPE_CLOSE_CONNECTION 5
#define GIOP_MSGTYPE_MESSAGE_ERROR 6
#define GIOP_MSGTYPE_FRAGMENT 7
#define GIOP_REPLYSTATUS_NO_EXCEPTION 0
#define GIOP_REPLYSTATUS_USER_EXCEPTION 1
#define GIOP_REPLYSTATUS_SYSTEM_EXCEPTION 2
#define GIOP_REPLYSTATUS_LOCATION_FORWARD 3
#define GIOP_SERVICECONTEXT_TRANSACTION_SERVICE 0
#define GIOP_SERVICECONTEXT_CODESETS 1
#define GIOP_PROFILE_IIOP 0
#define GIOP_PROFILE_MULTICOMPONENT 1
#define GIOP_PROFILE_ILU_IOP 0x494c5500
#define GIOP_PROFILE_ILU_SUNRPC_IOP 0x494c5501
#define GIOP_PROFILE_ILU_COURIER_IOP 0x494c5502
#define GIOP_PROFILE_ILU_UNUSED1_IOP 0x494c5503
#define GIOP_PROFILE_ILU_UNUSED2_IOP 0x494c5504
#define GIOP_PROFILE_ILU_UNUSED3_IOP 0x494c5505
#define GIOP_PROFILE_ILU_UNUSED4_IOP 0x494c5506
#define GIOP_PROFILE_ILU_UNUSED5_IOP 0x494c5507
#define IIOP_UNKNOWN_OBJECT 0
#define IIOP_OBJECT_HERE 1
#define IIOP_OBJECT_FORWARD 2
#define IOP_COMPONENTTAG_ORB_TYPE 6
#define IOP_COMPONENTTAG_CODE_SETS 1
#define IOP_COMPONENTTAG_SEC_NAME 14
#define IOP_COMPONENTTAG_ASSOCIATION_OPTIONS 13
#define IOP_COMPONENTTAG_GENERIC_SEC_MECH 12
struct giop_state {
u_int id; /* connection id */
};
struct state_list {
struct state_list *next;
struct giop_state state;
};
static struct state_list *connections = NULL;
static __inline struct giop_state *add_state (u_int id)
{
struct state_list *newstate = malloc (sizeof(*newstate));
newstate->state.id = id;
newstate->next = connections;
connections = newstate;
return (&newstate->state);
}
static __inline struct giop_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 char *quotechars (u_char * p, u_int len)
{
char *n = malloc ((4 * len) + 1);
u_int i, j;
if (!n)
return (NULL);
for (i = 0, j = 0; i < len; i++)
{
if (!isgraph ((int) (p[i])) || (p[i] == '\\'))
{
sprintf (n + j, "\\%3.3o", (int) p[i]);
j += strlen (n + j);
}
else
n[j++] = (char) p[i];
}
n[j] = 0;
return (n);
}
static char *figure_charset_name (u_int32_t charset_code)
{
switch (charset_code)
{
case IIOP_CHARSET_US_ASCII:
return ("(US ASCII)");
case IIOP_CHARSET_ISO_LATIN1:
return ("(ISO Latin1)");
case IIOP_CHARSET_UNICODE_UTF_8:
return ("(Unicode UTF-8)");
case IIOP_CHARSET_UNICODE_1_1:
return ("(Unicode UCS-2)");
default:
return ("");
}
}
#define SWAP_WORD(a) ( ((a) << 24) | \
(((a) << 8) & 0x00ff0000) | \
(((a) >> 8) & 0x0000ff00) | \
((u_int32_t)(a) >>24) )
static u_int32_t gtohl (u_int32_t val, u_int little_endian)
{
if (!little_endian)
return SWAP_WORD (val);
return (val);
}
static u_int print_ior (u_char * ior, u_int little_endian)
{
u_int32_t typeid_len, nprofiles, profile_len, profile_tag;
u_char *typeid, *profile_bytes, *orig_ior;
char * s;
u_int i;
orig_ior = ior;
typeid_len = gtohl (*(u_int32_t*)ior, little_endian);
ior += 4;
typeid = ior;
ior += ((typeid_len + 3) / 4) * 4;
nprofiles = gtohl (*(u_int32_t*)ior, little_endian);
ior += 4;
if (typeid_len > 0)
{
s = quotechars (typeid, typeid_len - 1);
PRINTF ("type=\"%s\"", s);
free (s);
}
for (i = 0; i < nprofiles; i++)
{
profile_tag = gtohl (*(u_int32_t*)ior, little_endian);
ior += 4;
profile_len = gtohl (*(u_int32_t*)ior, little_endian);
ior += 4;
profile_bytes = ior;
PUTS (",profile(");
switch (profile_tag)
{
case GIOP_PROFILE_IIOP:
{
u_int32_t little_endian, major, minor, hostnamelen, port;
u_int32_t okeylen, ncomponents, component_tag, j, component_len;
u_int component_little_endian;
u_char *hostname, *okey;
char *s;
little_endian = (profile_bytes[0] != 0);
major = profile_bytes[1];
minor = profile_bytes[2];
profile_bytes += 4;
hostnamelen = gtohl (*(u_int32_t*)profile_bytes, little_endian);
profile_bytes += 4;
hostname = profile_bytes;
profile_bytes += ((hostnamelen + 1) / 2) * 2;
if (little_endian)
port = profile_bytes[0] + (profile_bytes[1] << 8);
else port = profile_bytes[1] + (profile_bytes[0] << 8);
profile_bytes += (((((u_int32_t)profile_bytes) % 4) != 0) ? 4 : 2);
okeylen = gtohl (*(u_int32_t*)profile_bytes, little_endian);
profile_bytes += 4;
okey = profile_bytes;
s = quotechars (okey, okeylen);
PRINTF ("type=IIOP,hostname=\"%s\",port=%lu,objectkey=\"%s\"",
hostname, port, s);
free (s);
if (minor > 0)
{
profile_bytes += ((okeylen + 3) / 4) * 4;
ncomponents = gtohl (*(u_int32_t*)profile_bytes, little_endian);
profile_bytes += 4;
for (j = 0; j < ncomponents; j += 1)
{
component_tag = gtohl (*(u_int32_t*)profile_bytes, little_endian);
profile_bytes += 4;
component_len = gtohl (*(u_int32_t*)profile_bytes, little_endian);
profile_bytes += 4;
switch (component_tag)
{
case IOP_COMPONENTTAG_ORB_TYPE:
{
u_int32_t orb_type;
component_little_endian = (profile_bytes[0] != 0);
profile_bytes += 4;
orb_type = gtohl (*(u_int32_t*)profile_bytes,
component_little_endian);
profile_bytes += 4;
PRINTF (",orbtype=%lu");
}
break;
case IOP_COMPONENTTAG_CODE_SETS:
{
u_int32_t ncodesets, j, codeset;
component_little_endian = (profile_bytes[0] != 0);
profile_bytes += 4;
codeset = gtohl (*(u_int32_t*)profile_bytes,
component_little_endian);
profile_bytes += 4;
PRINTF (",char_codeset=%x%s",
codeset, figure_charset_name (codeset));
ncodesets = gtohl (*(u_int32_t*)profile_bytes,
component_little_endian);
profile_bytes += 4;
for (j = 0; j < ncodesets; j++)
{
codeset = gtohl (*(u_int32_t*)profile_bytes,
component_little_endian);
profile_bytes += 4;
}
codeset = gtohl (*(u_int32_t*)profile_bytes,
component_little_endian);
profile_bytes += 4;
PRINTF (",wchar_codeset=%x%s",
codeset, figure_charset_name (codeset));
ncodesets = gtohl (*(u_int32_t*)profile_bytes,
component_little_endian);
profile_bytes += 4;
for (j = 0; j < ncodesets; j++)
{
codeset = gtohl (*(u_int32_t*)profile_bytes,
component_little_endian);
profile_bytes += 4;
}
}
break;
case IOP_COMPONENTTAG_SEC_NAME:
PRINTF (",component(SEC_NAME,bytes=%lu)",
component_len);
break;
case IOP_COMPONENTTAG_ASSOCIATION_OPTIONS:
PRINTF (",component(ASSOCIATION_OPTIONS,bytes=%lu)",
component_len);
break;
case IOP_COMPONENTTAG_GENERIC_SEC_MECH:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -