TProxy + udpspeeder + udp2raw
{-# LANGUAGE OverloadedStrings #-}

module Udp2Raw where

import System.Process (proc, createProcess, waitForProcess)
import Control.Exception (throwIO)
import System.Exit (ExitCode(..))
import Data.Maybe (fromMaybe)

import Data.Text (Text)
import qualified Data.Text as Text

data RawMode
    = ICMP
    | UDP Int
    | FakeTCP Int
    deriving (Show, Eq)

rawModeToArg :: RawMode -> String
rawModeToArg rawMode =
    case rawMode of
        ICMP     -> "icmp"
        UDP _    -> "udp"
        FakeTCP _-> "faketcp"

getPort :: RawMode -> Maybe Int
getPort rawMode =
    case rawMode of
         ICMP       -> Nothing
         UDP p      -> Just p
         FakeTCP p  -> Just p

textToRawMode :: Text -> Maybe Int -> Maybe RawMode
textToRawMode t port =
    case Text.toLower (Text.strip t) of
        "icmp"    -> Just ICMP
        "udp"     -> Just(UDP (fromMaybe 443 port))
        "faketcp" -> Just(FakeTCP (fromMaybe 443 port))
        _         -> Nothing