Moved ATA driver into its own package
[movitz-core.git] / udp6-send.py
blobc756a48d08587b882e92f446324178c54e23d841
1 #! /usr/bin/env python
2 ######################################################################
3 ##
4 ## Copyright (C) 2001-2002,
5 ## Department of Computer Science, University of Tromsø, Norway.
6 ##
7 ## For distribution policy, see the accompanying file COPYING.
8 ##
9 ## Filename: udp6-send.py
10 ## Description: Send a simple (IPv6) UDP packet
11 ## Author: Frode Vatvedt Fjeld <frodef@acm.org>
12 ## Created at: Sun Mar 10 20:20:11 2002
13 ##
14 ## $Id: udp6-send.py,v 1.1 2004/01/13 11:04:59 ffjeld Exp $
15 ##
16 ######################################################################
18 import sys,time,socket
20 if len (sys.argv) != 4:
21 print "Usage: udp6-send <host> <port> <data>"
22 sys.exit (1);
24 host = sys.argv[1]
25 port = sys.argv[2]
26 data = sys.argv[3]
28 mtu = 1400
29 packets = (len (data) / mtu) + 1
31 # print "host:", host, "port:", port, "data:", data
33 af, socktype, proto, canonname, sa = \
34 socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_DGRAM)[0]
35 s = socket.socket (af, socktype, proto)
36 s.connect (sa)
37 for i in range (packets):
38 print "sending packet", i, ".."
39 s.send ("%d %d %s" % (i+1, packets, data[i*mtu:min(i*mtu+mtu, len (data))]))
40 time.sleep (0.1)
41 s.close ()