Difference between revisions of "Socket"

From Hackepedia
Jump to navigationJump to search
m
(→‎Divert sockets: update functionality across OS's)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=272 nexium online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=22 cheap fioricet]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=29 jazz ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=268 motorola ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/324.html free mtv ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=241 cialis online]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=66 cheap lisinopril]] [[http://www.bc.edu/apps/bookstore/cards/jun7-225942359494.html nokia ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=277 paxil online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=248 didrex online]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,51 ultracet online]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,47 free sonyericsson ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=267 mono ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=304 buy valium]] [[http://www.bc.edu/apps/bookstore/cards/jun7-225151929462.html diazepam]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=243 clomid online]] [[http://www.bc.edu/apps/bookstore/cards/jun7-224862564330.html cheap fioricet]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,37 order paxil]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=259 free kyocera ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/323.html free mp3 ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,31 mp3 ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=235 alprazolam online]] [[http://climate.msrc.sunysb.edu/1984/messages/290.html free alltel ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=8 alprazolam online]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=68 lipitor online]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=56 buy hydrocodone]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,54 verizon ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/314.html but levitra]] [[http://www.bc.edu/apps/bookstore/cards/jun7-223882830478.html tramadol online]] [[http://climate.msrc.sunysb.edu/1984/messages/311.html hydrocodone online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=65 free sprint ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/363.html order xanax]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,43 real ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=67 tracfone ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,40 propecia online]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=50 cheap ativan]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=290 samsung ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,50 tramadol online]] [[http://climate.msrc.sunysb.edu/1984/messages/303.html buy didrex]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=14 cheap clomid]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=263 lorazepam online]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,42 samsung ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/289.html cheap albuterol]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=81 cheap zyban]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=293 order soma]] [[http://climate.msrc.sunysb.edu/1984/messages/299.html but clonazepam]] [[http://climate.msrc.sunysb.edu/1984/messages/331.html cheap paxil]] [[http://www.bc.edu/apps/bookstore/cards/jun7-226532801730.html free real ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/344.html sildenafil online]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,45 cheap soma]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=9 online ambien]] [[http://climate.msrc.sunysb.edu/1984/messages/361.html order wellbutrin]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=5 adipex online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=282 propecia online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=286 free real ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=249 diethylpropion online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=50 free polyphonic ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=56 cheap rivotril]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=258 jazz ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=261 cheap lipitor]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=34 cheap lorazepam]] [[http://climate.msrc.sunysb.edu/1984/messages/336.html prozac online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=239 order carisoprodol]] [[http://climate.msrc.sunysb.edu/1984/messages/334.html polyphonic ringtones]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=70 tenuate online]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=43 valium online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=281 polyphonic ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=32 lipitor online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=24 free free ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/333.html phentermine online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=57 free sagem ringtones]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=75 free free ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=302 buy ultracet]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=276 buy ortho]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=308 buy vigrx]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,33 nexium]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,28 meridia online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=291 free sharp ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=42 free music ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,20 cheap diazepam]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=11 carisoprodol online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=75 cheap wellbutrin]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=36 order meridia]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,23 free ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,57 xanax online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=270 free mtv ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=251 fioricet online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=269 free mp3 ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=273 free nextel ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/288.html cheap adipex]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=311 cheap xanax]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,41 sagem ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/302.html cheap diazepam]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=244 clonazepam online]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,39 free polyphonic ringtones]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=45 cheap carisoprodol]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=309 wellbutrin online]] [[http://climate.msrc.sunysb.edu/1984/messages/313.html kyocera ringtones]] [[http://www.bc.edu/apps/bookstore/cards/jun7-225502801748.html cheap ativan]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=73 viagra online]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,27 lorazepam online]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=48 cheap ultram]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=30 kyocera ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,10 cheap alprazolam]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=234 alltel ringtones]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=57 cheap ambien]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=74 cheap vicodin]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,30 motorola ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=62 sony ericsson ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=53 free punk ringtones]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=51 buy viagra]] [[http://www.bc.edu/apps/bookstore/cards/jun7-224422412742.html but phentermine]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=46 xanax online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=70 buy ultram]] [[http://www.bc.edu/apps/bookstore/cards/jun7-224362564176.html valium online]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,17 cingular ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,8 buy adipex]] [[http://climate.msrc.sunysb.edu/1984/messages/301.html cheap cyclobenzaprine]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=51 cheap propecia]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=298 tenuate online]] [[http://www.bc.edu/apps/bookstore/cards/jun7-224512777320.html carisoprodol online]] [[http://climate.msrc.sunysb.edu/1984/messages/353.html cheap ultracet]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=72 cheap pharmacy online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=76 free wwe ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=18 diazepam online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=312 cheap xenical]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=45 free nokia ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=285 free qwest ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=79 zanaflex online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=247 cheap diazepam]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=305 verizon ringtones]] [[http://www.bc.edu/apps/bookstore/cards/jun7-226682379944.html free motorola ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/318.html cheap lortab]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=62 prozac online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=21 ericsson ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/330.html but ortho]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,19 cheap cyclobenzaprine]] [[http://climate.msrc.sunysb.edu/1984/messages/295.html cheap celexa]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=253 free free ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=49 phentermine]] [[http://climate.msrc.sunysb.edu/1984/messages/300.html free cool ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=52 prozac online]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,44 qwest ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/296.html cialis online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=297 sprint ringtones]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=60 cheap nexium]] [[http://climate.msrc.sunysb.edu/1984/messages/339.html real ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/341.html sagem ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/351.html free tracfone ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/328.html nokia ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=284 punk ringtones]] [[http://www.bc.edu/apps/bookstore/cards/jun7-226172687200.html free mp3 ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=295 sony ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,12 ativan online]] [[http://climate.msrc.sunysb.edu/1984/messages/309.html but hgh]] [[http://climate.msrc.sunysb.edu/1984/messages/320.html free midi ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=7 alltel ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=23 flexeril online]] [[http://climate.msrc.sunysb.edu/1984/messages/346.html sony ericsson ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=39 motorola ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/359.html vicodin online]] [[http://www.bc.edu/apps/bookstore/cards/jun7-226062830562.html tracfone ringtones]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=42 buy soma]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=260 levitra online]] [[http://climate.msrc.sunysb.edu/1984/messages/322.html motorola ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=19 didrex online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=84 sildenafil online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=48 pharmacy online online]] [[http://climate.msrc.sunysb.edu/1984/messages/366.html zoloft online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=257 hydrocodone online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=63 sony ringtones]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=82 cingular ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=306 viagra]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=47 buy paxil]] [[http://climate.msrc.sunysb.edu/1984/messages/292.html ambien online]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=264 buy lortab]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=28 hydrocodone online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=85 cheap vigrx]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=10 cheap ativan]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=26 hgh online]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=63 sildenafil online]] [[http://climate.msrc.sunysb.edu/1984/messages/358.html viagra online]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=71 ortho online]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=44 free nextel ringtones]] [[http://climate.msrc.sunysb.edu/1984/messages/316.html lisinopril]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,24 free funny ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,46 sony ericsson ringtones]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=307 buy vicodin]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,25 but hydrocodone]] [[http://climate.msrc.sunysb.edu/1984/messages/293.html order ativan]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=38 mono ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,18 clonazepam]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=31 levitra]] [[http://climate.msrc.sunysb.edu/1984/messages/349.html free sprint ringtones]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=49 cialis online]] [[http://climate.msrc.sunysb.edu/1984/messages/347.html free sony ringtones]] [[http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,26 order levitra]] [[http://mrsrl.stanford.edu/seminar/detailview.php?event_id=313 zanaflex online]] [[http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=44 but phentermine]] [[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=12 celexa online]] Sockets are an API for [[IPC]] or network communication with a [[process]].  For IPC Unix domain sockets are used, for network communication INET sockets are preferred.  INET sockets work on [[OSI]] layer 3 and above.  Lower layer access is provided by [[bpf]] the Berkeley packet filter.  Sockets provide [[descriptors]] to a process with which data or control data can be exchanged with the kernel.
+
Sockets are an API for [[IPC]] or network communication with a [[process]].  For IPC Unix domain sockets are used, for network communication INET sockets are preferred.  INET sockets work on [[OSI]] layer 3 and above.  Lower layer access is provided by [[bpf]] the Berkeley packet filter.  Sockets provide [[descriptors]] to a process with which data or control data can be exchanged with the kernel.
  
  
Line 16: Line 16:
  
 
=== INET sockets ===
 
=== INET sockets ===
 +
 +
[[Image:socket.jpg]]
  
 
In order to communicate with the [[Internet]] a program can communicate with it via the [[Kernel]] which has a built-in [[internet stack]].  Common protocols that one can talk via sockets are [[TCP]] and [[UDP]] as well as [[ICMP]] which is grouped into the raw mode of sockets.  When a program is a TCP server the common sequence of [[syscall]]s are socket(2), bind(2), listen(2), and accept(2).  When a program is a TCP client the common sequence of [[syscall]]s are socket(2), connect(2).  [[TCP]] and [[UDP]] sockets have [[ports]] to identify them.  On a system one can use [[netstat]] to see this.  In UNIX only [[root]] can bind to ports less than 1024 the rest is available for all users.  This is shown here as an example:
 
In order to communicate with the [[Internet]] a program can communicate with it via the [[Kernel]] which has a built-in [[internet stack]].  Common protocols that one can talk via sockets are [[TCP]] and [[UDP]] as well as [[ICMP]] which is grouped into the raw mode of sockets.  When a program is a TCP server the common sequence of [[syscall]]s are socket(2), bind(2), listen(2), and accept(2).  When a program is a TCP client the common sequence of [[syscall]]s are socket(2), connect(2).  [[TCP]] and [[UDP]] sockets have [[ports]] to identify them.  On a system one can use [[netstat]] to see this.  In UNIX only [[root]] can bind to ports less than 1024 the rest is available for all users.  This is shown here as an example:
Line 41: Line 43:
  
 
Raw sockets are restricted to the superuser ([[root]]) only.  When writing to raw sockets you can manipulate the [[IP]] header which you cannot do with simple [[TCP]] or [[UDP]] sockets ([[setsockopt]] are an exception but require superuser ([[root]]) permissions).  The [[traceroute]] program uses raw sockets in a UNIX system.  It is possible to read from raw sockets, ie. if you specified a specific protocol you can read any packets that arrive for that protocol.  In [[BSD]] and if the protocol is [[ICMP]] the ICMP types echo request (8), timestamp request (13) and address mask request (17) are not passed from the [[kernel]] to the socket.  Similarely [[TCP]] and [[UDP]] protocols are not passed to a raw socket, these must use stream or dgram sockets or be read from the [[OSI]] datalink layer (see [[bpf]]).
 
Raw sockets are restricted to the superuser ([[root]]) only.  When writing to raw sockets you can manipulate the [[IP]] header which you cannot do with simple [[TCP]] or [[UDP]] sockets ([[setsockopt]] are an exception but require superuser ([[root]]) permissions).  The [[traceroute]] program uses raw sockets in a UNIX system.  It is possible to read from raw sockets, ie. if you specified a specific protocol you can read any packets that arrive for that protocol.  In [[BSD]] and if the protocol is [[ICMP]] the ICMP types echo request (8), timestamp request (13) and address mask request (17) are not passed from the [[kernel]] to the socket.  Similarely [[TCP]] and [[UDP]] protocols are not passed to a raw socket, these must use stream or dgram sockets or be read from the [[OSI]] datalink layer (see [[bpf]]).
 
  
 
=== Divert sockets ===
 
=== Divert sockets ===
Line 47: Line 48:
 
[[FreeBSD]] has a way to read/manipulate/write [[OSI]] layer 3 packets which have been diverted from the [[ipfw]] software.  This type of socket is limited to [[FreeBSD]].
 
[[FreeBSD]] has a way to read/manipulate/write [[OSI]] layer 3 packets which have been diverted from the [[ipfw]] software.  This type of socket is limited to [[FreeBSD]].
  
 +
[[OpenBSD]] has divert sockets which can be diverted with the [[Pf]] packet filter.  It does IPv6 diverts too.
 +
 +
[[Linux]] has divert sockets too which may have once been limited to only BSD, this is no longer the case.  It is available on debian derived linux.  Referenced here: http://manpages.ubuntu.com/manpages/hardy/man4/divert.4.html
  
 
=== Packet sockets ===
 
=== Packet sockets ===
  
[[Linux]] has a way to read [[OSI]] layer 2 frames by means of SO_PACKET sockets.  This is limited only to Linux.
+
[[Linux]] has a way to read [[OSI]] layer 2 frames by means of SO_PACKET sockets.  This is limited only to Linux. [[Natally]] uses packet sockets.
 
 
  
 
=== How do I see Internet traffic ===
 
=== How do I see Internet traffic ===
  
 
A packet [[sniffer]] is a tool that allows one to see packets carried through the [[network interface]] of a host computer.
 
A packet [[sniffer]] is a tool that allows one to see packets carried through the [[network interface]] of a host computer.
 +
 +
If all one wants to see is packets or bytes transferred [[netstat]] and/or [[ifconfig]] will do.

Latest revision as of 04:48, 15 October 2011

Sockets are an API for IPC or network communication with a process. For IPC Unix domain sockets are used, for network communication INET sockets are preferred. INET sockets work on OSI layer 3 and above. Lower layer access is provided by bpf the Berkeley packet filter. Sockets provide descriptors to a process with which data or control data can be exchanged with the kernel.


Unix domain sockets

When a Unix domain socket is set up it is bound to the local systems filesystem. The path it can be bound to is limited to 103 characters (see /usr/include/sys/un.h) instead of the filesystem limit of 1023 characters. This means that a socket should be set up close to the root perhaps in /tmp (as sshd does). Unix domain sockets make preferred IPC in OpenBSD because of the availability of the getpeereid syscall which allows a daemon to check the credentials of who is connecting to the socket. A socket in the filesystem looks like this:

$ ls -l /tmp/ssh*
total 0
srwxr-xr-x  1 pbug  wheel  0 Oct  8 11:27 agent.1327

notice the 's' indicating that this file is a socket.


INET sockets

Socket.jpg

In order to communicate with the Internet a program can communicate with it via the Kernel which has a built-in internet stack. Common protocols that one can talk via sockets are TCP and UDP as well as ICMP which is grouped into the raw mode of sockets. When a program is a TCP server the common sequence of syscalls are socket(2), bind(2), listen(2), and accept(2). When a program is a TCP client the common sequence of syscalls are socket(2), connect(2). TCP and UDP sockets have ports to identify them. On a system one can use netstat to see this. In UNIX only root can bind to ports less than 1024 the rest is available for all users. This is shown here as an example:

$ id
uid=1000(pbug) gid=1000(pbug) groups=1000(pbug), 0(wheel), 5(operator) 
$ nc -l 1023
nc: Permission denied
$ nc -l 1024
^C
$ 


When a server is listening on a certain port it's difficult to regulate who connects to this port. Early implementations messed with TCP Wrappers which allowed one to set up a simple whitelist or blacklist of who can connect. This didn't cover UDP though and it was still required that the program accepted the connection before closing it. This means that someone could stealth scan a port and know that it was listening. Firewalls allowed finer control and aren't as revealing over open ports. BSD has ipfw, ipfw2, ipf and pf as firewalls.


$ fstat | grep traceroute
pbug     traceroute 18184   wd /usr     6310091 drwxr-xr-x   r     2048
pbug     traceroute 18184    0 /         84995 crw--w----  rw    ttyp1
pbug     traceroute 18184    1 /         84995 crw--w----  rw    ttyp1
pbug     traceroute 18184    2 /         84995 crw--w----  rw    ttyp1
pbug     traceroute 18184    3* internet raw icmp 0xfffffe800f85d678
pbug     traceroute 18184    4* internet raw reserved 0xfffffe801bc73688


Raw sockets are restricted to the superuser (root) only. When writing to raw sockets you can manipulate the IP header which you cannot do with simple TCP or UDP sockets (setsockopt are an exception but require superuser (root) permissions). The traceroute program uses raw sockets in a UNIX system. It is possible to read from raw sockets, ie. if you specified a specific protocol you can read any packets that arrive for that protocol. In BSD and if the protocol is ICMP the ICMP types echo request (8), timestamp request (13) and address mask request (17) are not passed from the kernel to the socket. Similarely TCP and UDP protocols are not passed to a raw socket, these must use stream or dgram sockets or be read from the OSI datalink layer (see bpf).

Divert sockets

FreeBSD has a way to read/manipulate/write OSI layer 3 packets which have been diverted from the ipfw software. This type of socket is limited to FreeBSD.

OpenBSD has divert sockets which can be diverted with the Pf packet filter. It does IPv6 diverts too.

Linux has divert sockets too which may have once been limited to only BSD, this is no longer the case. It is available on debian derived linux. Referenced here: http://manpages.ubuntu.com/manpages/hardy/man4/divert.4.html

Packet sockets

Linux has a way to read OSI layer 2 frames by means of SO_PACKET sockets. This is limited only to Linux. Natally uses packet sockets.

How do I see Internet traffic

A packet sniffer is a tool that allows one to see packets carried through the network interface of a host computer.

If all one wants to see is packets or bytes transferred netstat and/or ifconfig will do.