[nw0556:~] j05056% telnet www.1pondo.tv 80 Trying 38.118.195.186... Connected to 1pondo.tv. Escape character is '^]'. GET/index.html HTTP/1.0 <html><head><title>Error 501 Not Implemented </title></head><body bgcolor=#ffffff><h2>Error 501 Not Implemented </h2><p><i>Powered by <a href="http://errors.zeus.com/">Zeus Technology</a></i></body></html> Connection closed by foreign host.
server.c ・"#include <stdlib.h>"を追加 ・DATAFILEを"/Users/j05056/jikken2/tcpip/data/data.txt"に変更 client.c ・"#include <stdlib.h>"を追加 ・HOST_NAMEを"nw0556.st.ie.u-ryukyu.ac.jp"に変更
[nw0556:~/jikken2/report6/sample1] j05056% client Connected. Input Keyword = warning: this program uses gets(), which is unsafe. yama Keyword = [yama] / Data = [kawa] Input Keyword = abc Keyword = [abc] / Data = [ABC] Input Keyword = 123 Keyword = [123] / Data = [456] Input Keyword = xxx Keyword = [xxx] / Data = [yyy] Input Keyword = shiro Keyword = [shiro] / Data = [kuro]
Connect socket生成、host nameやhost addressの設定をし、接続の準備をする Disconnect 接続を閉じる Send Data データ送信 Recv Data データ受信
[nw0556:~/jikken2/report6/tcpip] j05056% ./client_noinetd yama kawa 123 456 xyz XYZ
[nw0556:~/jikken2/report6/tipip] j05056% ./htmlget http://www.yahoo.co.jp/ を取得します。 GET / HTTP/1.0 Host: www.yahoo.co.jp:80 HTTP/1.1 200 OK Date: Sun, 10 Dec 2006 13:21:55 GMT P3P: policyref="http://privacy.yahoo.co.jp/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV" Expires: -1 Pragma: no-cache Cache-Control: no-cache Connection: close Content-Type: text/html; charset=euc-jp < html > < head > < meta http-equiv="Content-Type" content="text/html; charset=euc-jp" > 省略
[nw0556:~/jikken2/report6/tipip] j05056% ./portscan "127.0.0.1" PortScan Start!! 80 427 548 631 There are using
[nw0556:~/jikken2/report6/tipip] j05056% ./bufovf before buf(Len:0) = dmy(Len:0) = warning: this program uses gets(), which is unsafe. 1234567890123456789012345678901234567890 after buf(Len:40) = 1234567890123456789012345678901234567890 dmy(Len:0) = Segmentation fault
gets()関数を使っているためだと考えられる。 gets()関数は配列の長さを指定することができないため、配列以上の文字が入力されるのを防ぐことができず、そのままdmy[]に値を書き込んでしまう。
fgets()関数を使えばよい。 fgets()関数は指定した配列より長い値を入力すると、指定したバッファのサイズを超えないように書き込むという特徴があるからである。