⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldltest.c

📁 7号信令功能代码,为开源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** @(#) ldltest.c,v LiS-2_16_18-8(1.1.1.2.8.1) 2004/01/12 23:33:16 ----------------------------------------------------------------------------- Copyright (c) 2003-2004  OpenSS7 Corporation <http://www.openss7.com> All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------------------- U.S. GOVERNMENT RESTRICTED RIGHTS.  If you are licensing this Software on behalf of the U.S. Government ("Government"), the following provisions apply to you.  If the Software is supplied by the Department of Defense ("DoD"), it is classified as "Commercial Computer Software" under paragraph 252.227-7014 of the DoD Supplement to the Federal Acquisition Regulations ("DFARS") (or any successor regulations) and the Government is acquiring only the license rights granted herein (the license rights customarily provided to non-Government users).  If the Software is supplied to any unit or agency of the Government other than DoD, it is classified as "Restricted Computer Software" and the Government's rights in the Software are defined in paragraph 52.227-19 of the Federal Acquisition Regulations ("FAR") (or any success regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Commercial licensing and support of this software is available from OpenSS7 Corporation at a fee.  See http://www.openss7.com/ ----------------------------------------------------------------------------- Last Modified 2004/01/12 23:33:16 by brian ----------------------------------------------------------------------------- ldltest.c,v Revision 1.1.1.2.8.1  2004/01/12 23:33:16  brian - Updated LiS-2.16.18 gcom release to autoconf. Revision 1.1.1.2.4.2  2003/12/15 23:35:06  brian - Tried to reduce number of patch lines. Revision 1.1.1.2.4.1  2003/12/10 11:09:29  brian Start of autoconf changes. *****************************************************************************/#ident "@(#) ldltest.c,v LiS-2_16_18-8(1.1.1.2.8.1) 2004/01/12 23:33:16"static char const ident[] =    "ldltest.c,v LiS-2_16_18-8(1.1.1.2.8.1) 2004/01/12 23:33:16";/* *  ldltest: Test program for dlpi driver * *  Copyright (C) 1998 Ole Husgaard (sparre@login.dknet.dk) * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * *  Notes: *    1) The PING will only work if the target is local or if an *       intermediary router does proxy ARP for our target. *    2) Under Linux 2.2, the native IP stack will NOT respond to a ping *       on interface loopback from this utility. This is due to some *       optimizations in the native IP implementation. Use another instance *       of this utility to do replies. *    3) This source is ugly. */#ident "@(#) LiS ldltest.c 2.13 9/9/03"#ifndef LINUX#define LINUX 2#endif#ifdef HAVE_UNISTD_H#include <unistd.h>#else#include <linux/unistd.h>	/* To get around a glibc problem with old kernels. */#endif#include <sys/types.h>#include <sys/time.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <unistd.h>#include <stdlib.h>#include <fcntl.h>#include <string.h>#include <signal.h>#include <setjmp.h>#include <ctype.h>#include <stdio.h>#include <errno.h>#include <assert.h>#include <arpa/inet.h>#ifdef _GNU_SOURCE#include <getopt.h>#endif#include <sys/stropts.h>#include <sys/dlpi.h>#include <sys/ldl.h>#if !defined(_I386_TYPES_H) && !defined(_ASM_IA64_TYPES_H)typedef unsigned char __u8;typedef unsigned short __u16;typedef unsigned int __u32;#endif#define ARPHRD_ETHER	1#define ARPHRD_IEEE802	6#define ARPOP_REQUEST	1#define ARPOP_REPLY	2#define ETH_P_IP	0x0800#define ETH_P_ARP	0x0806#define	ETH_P_RAW	0x00FF#define __LITTLE_ENDIAN_BITFIELD/* *  Ethernet header structure, snipped from <linux/if_ether.h> */#define ETH_ALEN 6		/* Octets in one ethernet addr */struct ethhdr {      unsigned char   h_dest[ETH_ALEN];	/* destination eth addr */      unsigned char   h_source[ETH_ALEN];	/* source ether addr */      unsigned short  h_proto;	/* packet type ID field */};struct eth_llc_hdr {		/* 802.2 header */      unsigned char   h_dest[ETH_ALEN];	/* destination eth addr */      unsigned char   h_source[ETH_ALEN];	/* source ether addr */      unsigned char   h_len_hi;	/* length indicator */      unsigned char   h_len_lo;	/* length indicator */      unsigned char   llc_dsap;	/* LLC header */      unsigned char   llc_ssap;      unsigned char   llc_cmnd;};/* * Token ring header, snipped from ldl.c * * Note that there is no length field as there is in an Ethernet * header.  IP packet types have to be encoded inside a SNAP header * beyond the LLC header. */#define	TR_ALEN		6typedef struct tr_hdr {      unsigned char   acf;      unsigned char   fcf;      unsigned char   dst_addr[TR_ALEN];      unsigned char   src_addr[TR_ALEN];      /*       * Routing control bytes: Only present if the routing bit       * is set in the first byte of the src_addr.       */      unsigned char   bl;	/* brdcst & lgth */      unsigned char   df;	/* direction & lrgst frm bits */} tr_hdr_t;/* * After a variable amount of routing data you come to the * LLC header. */typedef struct tr_llc_frm_hdr {      unsigned char   llc_dsap;	/* destination SAP address */      unsigned char   llc_ssap;	/* source SAP address */      unsigned char   llc_ctl[1];	/* control field */} tr_llc_frm_hdr_t;/* * A few bits from the token ring header. */#define SADDR_0_RTE_PRES        0x80	/* 1=rte info present, 0=none */#define RCF_0_LLLLL             0x1F	/* length bits */#define FCF_FF          	0xC0	/* frame type bits */#define     FCF_MAC     	0x00	/* MAC frame */#define     FCF_LLC     	0x40	/* LLC frame *//* *  IP header structure, snipped from <linux/ip.h> */struct iphdr {#if defined(__LITTLE_ENDIAN_BITFIELD)      __u8            ihl:4,                      version:4;#elif defined (__BIG_ENDIAN_BITFIELD)      __u8            version:4,                      ihl:4;#else#error  "Please fix byteorder"#endif      __u8            tos;      __u16           tot_len;      __u16           id;      __u16           frag_off;      __u8            ttl;      __u8            protocol;      __u16           check;      __u32           saddr;      __u32           daddr;      /*       * The options start here.        */};/* *  ICMP header structure, snipped from <linux/icmp.h> */struct icmphdr {      __u8            type;      __u8            code;      __u16           checksum;      union {	    struct {		  __u16           id;		  __u16           sequence;	    } echo;	    __u32           gateway;      } un;};#define ICMP_ECHOREPLY          0	/* Echo Reply */#define ICMP_ECHO               8	/* Echo Request *//* *  Ethernet ARP header structure, snipped from <linux/if_arp.h> */struct arphdr {      unsigned short  ar_hrd;	/* format of hardware address */      unsigned short  ar_pro;	/* format of protocol address */      unsigned char   ar_hln;	/* length of hardware address */      unsigned char   ar_pln;	/* length of protocol address */      unsigned short  ar_op;	/* ARP opcode (command) */#if 0      /*       *  Ethernet looks like this : This bit is variable sized however...       */      unsigned char   ar_sha[ETH_ALEN];	/* sender hardware address */      unsigned char   ar_sip[4];	/* sender IP address */      unsigned char   ar_tha[ETH_ALEN];	/* target hardware address */      unsigned char   ar_tip[4];	/* target IP address */#endif};/* *  Our ICMP PING packet structure */struct ping_pkt {      struct iphdr    ip_hdr;      struct icmphdr  icmp_hdr;      struct timeval  tv;      char            filler[48];};/* *  Variables specified at the command line */int             verbose;	/* verbose level */int             arp_respond;	/* respond to ARP queries */int             echo_respond;	/* respond to ICMP PING packets */unsigned long   pkt_count;	/* Number of packets to send */struct in_addr  my_ip_addr,                target_ip_addr;	/* Local and remote IP number */char           *interface;	/* Interface name */unsigned long   framing;	/* Link encapsulation type */int             test_ping;	/* send an LLC TEST cmnd instead of IP pkt */int             xid_ping;	/* send an LLC XID cmnd instead of IP pkt */int             test_xid;	/* test_ping || xid_ping */int             saps_set;	/* -S present */#define MAX_DL_ADDR_LEN 128#define MAX_DL_SAP_LEN 64/* *  Our MAC addresses */int             addr_len;	/* Data Link address length */int             sap_len;	/* Data Link SAP length */int             sap_first;	/* Flag: SAP first in DLSAP */int             hw_type;	/* ARP hardware type */int             mac_type;	/* DLPI MAC type from info ack */unsigned char   my_addr[MAX_DL_ADDR_LEN];unsigned char   my_brd_addr[MAX_DL_ADDR_LEN];unsigned char   my_dlsap[MAX_DL_ADDR_LEN + MAX_DL_SAP_LEN];unsigned char   my_sap[MAX_DL_SAP_LEN];unsigned char   my_llc_sap[MAX_DL_SAP_LEN];volatile int    got_target_addr;unsigned char   target_addr[MAX_DL_ADDR_LEN];unsigned char   target_dlsap[MAX_DL_ADDR_LEN + MAX_DL_SAP_LEN];unsigned char   target_sap[MAX_DL_SAP_LEN];/* * Procedure forward declarations */extern int      do_promiscon(int fd, unsigned long level);extern int      send_test_xid(int fd, int cmnd);/* *  ldl flags */unsigned long   ldl_flags = LDLFLAG_DEFAULT;/**************************************************************//* *//* * Utilities for dumping data  *//* *//**************************************************************/char           *hex(unsigned char c){      static char     s[3];      static char     h[16] = "0123456789abcdef";      s[0] = h[c >> 4];      s[1] = h[c & 15];      s[2] = '\0';      return s;}void dumpbytes(char *prompt, unsigned char *data, int len){      if (!verbose)	    return;      printf("%s: ", prompt);      while (len--) {	    printf("%s%s", hex(*data), (len) ? ":" : "");	    ++data;      }      printf("\n");}void dumpbuf(struct strbuf buf){      int             i,                      j;      int             lines = (buf.len == 0) ? 0 : ((buf.len - 1) >> 4) + 1;      char            s1[128],                      s2[128];      if (!verbose)	    return;      printf("  Len = %d  MaxLen = %d\n", buf.len, buf.maxlen);      for (i = 0; i < lines; ++i) {	    strcpy(s1, "  ");	    strcpy(s2, "  ");	    for (j = 0; j < 16; ++j) {		  if (16 * i + j < buf.len) {			unsigned char   c = buf.buf[16 * i + j];			strcat(s1, hex(c));			strcat(s1, " ");			if (isprint(c)) {			      char            s3[2];			      s3[0] = c;			      s3[1] = '\0';			      strcat(s2, s3);			}			else			      strcat(s2, ".");		  }		  else {			strcat(s1, "   ");			strcat(s2, " ");		  }		  if (j == 7) {			strcat(s1, " ");			strcat(s2, " ");		  }	    }	    printf("  %s  %s\n", s1, s2);      }}void dumpaddr(char *prompt, unsigned char *addr, int addrlen){      if (!verbose)	    return;      printf("%s: ", prompt);      if (addrlen) {	    printf("%02x", (int) *addr++);	    --addrlen;      }      else {	    printf("(none)\n");	    return;      }      while (addrlen--)	    printf(":%02x", (int) *addr++);      printf("\n");}/**************************************************************//* *//* * Utilities for dlsap sap/addr ordering abstraction  *//* *//**************************************************************//* *  Return pointer to address part of dlsap */char           *dlsap_addr(char *dlsap){      return (sap_first) ? dlsap + sap_len : dlsap;}/* *  Return pointer to sap part of dlsap */char           *dlsap_sap(char *dlsap){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -