Skip to content

Commit

Permalink
Added MTU size check
Browse files Browse the repository at this point in the history
* Convert mtu to int at argparse
* Check mtu for int
* Bheck for mtu >= 68 bytes
* Check for mtu <= 65535 bytes
  • Loading branch information
kb1lqc committed Mar 11, 2018
1 parent 1df4b66 commit 90af4fe
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion faradayio_cli/faradayio_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setupArgparse():
help="Set serial port baud rate")
parser.add_argument("-l", "--loopback", action="store_true",
help="Use software loopback serial port")
parser.add_argument("-m", "--mtu", default=1500,
parser.add_argument("-m", "--mtu", default=1500, type=int,
help="Set Maximum Transmission Unit (MTU)")
parser.add_argument("-p", "--port", default="/dev/ttyUSB0",
help="Physical serial port of radio")
Expand Down Expand Up @@ -95,6 +95,14 @@ def checkUserInput(args):
if not isinstance(args.loopback, bool):
raise TypeError

# Check Maximum Transmission Unit (MTU)
# Expect and integer
if not isinstance(args.mtu, int):
raise TypeError
# Expect a value between 68-65535 per RFC 791
if not 68 <= args.mtu <= 65535:
raise ValueError("--mtu must be between 68 and 65535 bytes")


def setupSerialPort(loopback, port, baud, readtimeout, writetimeout):
"""Sets up serial port by connecting to phsyical or software port.
Expand Down

0 comments on commit 90af4fe

Please sign in to comment.